diff --git a/migrator/migrator.go b/migrator/migrator.go index af1385e2..91bf60a7 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -390,7 +390,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy alterColumn := false // check size - if length, _ := columnType.Length(); length != int64(field.Size) { + if length, ok := columnType.Length(); length != int64(field.Size) { if length > 0 && field.Size > 0 { alterColumn = true } else { @@ -399,7 +399,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy matches := regRealDataType.FindAllStringSubmatch(realDataType, -1) matches2 := regFullDataType.FindAllStringSubmatch(fullDataType, -1) if (len(matches) == 1 && matches[0][1] != fmt.Sprint(field.Size) || !field.PrimaryKey) && - (len(matches2) == 1 && matches2[0][1] != fmt.Sprint(length)) { + (len(matches2) == 1 && matches2[0][1] != fmt.Sprint(length) && ok) { alterColumn = true } } diff --git a/tests/migrate_test.go b/tests/migrate_test.go index 789a5e45..3d15bf2c 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -90,7 +90,7 @@ func TestAutoMigrateSelfReferential(t *testing.T) { } func TestSmartMigrateColumn(t *testing.T) { - fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()] + fullSupported := map[string]bool{"mysql": true}[DB.Dialector.Name()] type UserMigrateColumn struct { ID uint