mirror of https://github.com/go-gorm/gorm.git
autoIndex should throw an error on failed
This commit is contained in:
parent
0a51f6cdc5
commit
26262ef9bb
12
scope.go
12
scope.go
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue