mirror of https://github.com/go-gorm/gorm.git
Create index automatically when create table
This commit is contained in:
parent
d1892d3177
commit
be45d8312e
|
@ -557,7 +557,10 @@ func (scope *Scope) createTable() *Scope {
|
|||
if len(primaryKeys) > 0 && !primaryKeyInColumnType {
|
||||
primaryKeyStr = fmt.Sprintf(", PRIMARY KEY (%v)", strings.Join(primaryKeys, ","))
|
||||
}
|
||||
|
||||
scope.Raw(fmt.Sprintf("CREATE TABLE %v (%v %v) %s", scope.QuotedTableName(), strings.Join(tags, ","), primaryKeyStr, scope.getTableOptions())).Exec()
|
||||
|
||||
scope.autoIndex()
|
||||
return scope
|
||||
}
|
||||
|
||||
|
@ -629,9 +632,8 @@ func (scope *Scope) autoMigrate() *Scope {
|
|||
}
|
||||
scope.createJoinTable(field)
|
||||
}
|
||||
}
|
||||
|
||||
scope.autoIndex()
|
||||
}
|
||||
return scope
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue