AutoMigrate should auto create indexes, close #3486

This commit is contained in:
Jinzhu 2020-09-18 21:50:11 +08:00
parent c9165fe3ca
commit 089939c767
1 changed files with 9 additions and 0 deletions

View File

@ -133,6 +133,15 @@ func (m Migrator) AutoMigrate(values ...interface{}) error {
}
}
}
for _, idx := range stmt.Schema.ParseIndexes() {
if !tx.Migrator().HasIndex(value, idx.Name) {
if err := tx.Migrator().CreateIndex(value, idx.Name); err != nil {
return err
}
}
}
return nil
}); err != nil {
return err