diff --git a/schema/field.go b/schema/field.go index 8df568ab..04be47cf 100644 --- a/schema/field.go +++ b/schema/field.go @@ -69,7 +69,6 @@ type Field struct { DefaultValueInterface interface{} NotNull bool Unique bool - UniqueIndex string Comment string Size int Precision int @@ -88,6 +87,12 @@ type Field struct { Set func(context.Context, reflect.Value, interface{}) error Serializer SerializerInterface NewValuePool FieldNewValuePool + + // In some db (e.g. MySQL), Unique and UniqueIndex are indistinguishable. + // When a column has a (not Mul) UniqueIndex, Migrator always reports its gorm.ColumnType is Unique. + // It causes field unnecessarily migration. + // Therefore, we need to record the UniqueIndex on this column (exclude Mul UniqueIndex) for MigrateColumnUnique. + UniqueIndex string } func (field *Field) BindName() string {