Skip to content

Commit

Permalink
AutoMigrate should auto create indexes, close #3486
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Sep 18, 2020
1 parent c9165fe commit 089939c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions migrator/migrator.go
Expand Up @@ -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
Expand Down

0 comments on commit 089939c

Please sign in to comment.