Fix unexpected alter table in auto migration

This commit is contained in:
Defool 2022-12-24 22:04:19 +08:00
parent 794edad60e
commit 9c5ca8130e

View File

@ -445,7 +445,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy
}
}
if !isSameType {
if !isSameType && fullDataType != "mediumtext" && fullDataType != "longtext" {
// check size
if length, ok := columnType.Length(); length != int64(field.Size) {
if length > 0 && field.Size > 0 {
@ -477,14 +477,6 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy
}
}
// check unique
if unique, ok := columnType.Unique(); ok && unique != field.Unique {
// not primary key
if !field.PrimaryKey {
alterColumn = true
}
}
// check default value
if !field.PrimaryKey {
currentDefaultNotNull := field.HasDefaultValue && !strings.EqualFold(field.DefaultValue, "NULL")