mirror of https://github.com/go-gorm/gorm.git
Added missing field name quoting for `ALTER TABLE' and `CREATE INDEX' statements.
This commit is contained in:
parent
308c96ee4c
commit
e31752757a
|
@ -530,7 +530,7 @@ func (scope *Scope) addForeignKey(field string, dest string, onDelete string, on
|
||||||
var table = scope.TableName()
|
var table = scope.TableName()
|
||||||
var keyName = fmt.Sprintf("%s_%s_foreign", table, field)
|
var keyName = fmt.Sprintf("%s_%s_foreign", table, field)
|
||||||
var query = `ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s ON DELETE %s ON UPDATE %s;`
|
var query = `ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s ON DELETE %s ON UPDATE %s;`
|
||||||
scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), keyName, field, dest, onDelete, onUpdate)).Exec()
|
scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.Quote(keyName), scope.Quote(field), scope.Quote(dest), onDelete, onUpdate)).Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scope *Scope) removeIndex(indexName string) {
|
func (scope *Scope) removeIndex(indexName string) {
|
||||||
|
@ -548,7 +548,7 @@ func (scope *Scope) autoMigrate() *Scope {
|
||||||
if !scope.Dialect().HasColumn(scope, tableName, field.DBName) {
|
if !scope.Dialect().HasColumn(scope, tableName, field.DBName) {
|
||||||
if field.IsNormal {
|
if field.IsNormal {
|
||||||
sqlTag := scope.generateSqlTag(field)
|
sqlTag := scope.generateSqlTag(field)
|
||||||
scope.Raw(fmt.Sprintf("ALTER TABLE %v ADD %v %v;", quotedTableName, field.DBName, sqlTag)).Exec()
|
scope.Raw(fmt.Sprintf("ALTER TABLE %v ADD %v %v;", quotedTableName, scope.Quote(field.DBName), sqlTag)).Exec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scope.createJoinTable(field)
|
scope.createJoinTable(field)
|
||||||
|
|
Loading…
Reference in New Issue