autoIndex should throw an error on failed

This commit is contained in:
Wing Gao 2017-11-28 13:05:10 +08:00
parent 0a51f6cdc5
commit 26262ef9bb
1 changed files with 10 additions and 2 deletions

View File

@ -1228,11 +1228,19 @@ func (scope *Scope) autoIndex() *Scope {
} }
for name, columns := range indexes { for name, columns := range indexes {
scope.NewDB().Model(scope.Value).AddIndex(name, columns...) db := scope.NewDB().Model(scope.Value).AddIndex(name, columns...)
if db.Error != nil {
scope.db.Error = db.Error
return scope
}
} }
for name, columns := range uniqueIndexes { for name, columns := range uniqueIndexes {
scope.NewDB().Model(scope.Value).AddUniqueIndex(name, columns...) db := scope.NewDB().Model(scope.Value).AddUniqueIndex(name, columns...)
if db.Error != nil {
scope.db.Error = db.Error
return scope
}
} }
return scope return scope