Merge 51abb15f12885218161e2bd7ffb9c2b23c63ec0e into 373bcf7aca01ef76c8ba5c3bc1ff191b020afc7b

This commit is contained in:
piyongcai 2022-05-16 01:42:22 +00:00 committed by GitHub
commit 580de0696c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -440,7 +440,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy
} }
// check unique // check unique
if unique, ok := columnType.Unique(); ok && unique != field.Unique { if unique, ok := columnType.Unique(); ok && !(unique == field.Unique || field.UniqueIndex == unique) {
// not primary key // not primary key
if !field.PrimaryKey { if !field.PrimaryKey {
alterColumn = true alterColumn = true

View File

@ -68,6 +68,7 @@ type Field struct {
DefaultValue string DefaultValue string
DefaultValueInterface interface{} DefaultValueInterface interface{}
NotNull bool NotNull bool
UniqueIndex bool
Unique bool Unique bool
Comment string Comment string
Size int Size int
@ -114,6 +115,7 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
HasDefaultValue: utils.CheckTruth(tagSetting["AUTOINCREMENT"]), HasDefaultValue: utils.CheckTruth(tagSetting["AUTOINCREMENT"]),
NotNull: utils.CheckTruth(tagSetting["NOT NULL"], tagSetting["NOTNULL"]), NotNull: utils.CheckTruth(tagSetting["NOT NULL"], tagSetting["NOTNULL"]),
Unique: utils.CheckTruth(tagSetting["UNIQUE"]), Unique: utils.CheckTruth(tagSetting["UNIQUE"]),
UniqueIndex: utils.CheckTruth(tagSetting["UNIQUEINDEX"]),
Comment: tagSetting["COMMENT"], Comment: tagSetting["COMMENT"],
AutoIncrementIncrement: 1, AutoIncrementIncrement: 1,
} }