forked from mirror/gorm
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 {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue