Create index automatically when create table

This commit is contained in:
Jinzhu 2016-01-04 19:22:42 +08:00
parent d1892d3177
commit be45d8312e
1 changed files with 4 additions and 2 deletions

View File

@ -557,7 +557,10 @@ func (scope *Scope) createTable() *Scope {
if len(primaryKeys) > 0 && !primaryKeyInColumnType { if len(primaryKeys) > 0 && !primaryKeyInColumnType {
primaryKeyStr = fmt.Sprintf(", PRIMARY KEY (%v)", strings.Join(primaryKeys, ",")) 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.Raw(fmt.Sprintf("CREATE TABLE %v (%v %v) %s", scope.QuotedTableName(), strings.Join(tags, ","), primaryKeyStr, scope.getTableOptions())).Exec()
scope.autoIndex()
return scope return scope
} }
@ -629,9 +632,8 @@ func (scope *Scope) autoMigrate() *Scope {
} }
scope.createJoinTable(field) scope.createJoinTable(field)
} }
scope.autoIndex()
} }
scope.autoIndex()
return scope return scope
} }