Escaping table names when AddForeignKey

This commit is contained in:
Jinzhu 2015-02-28 09:25:05 +08:00
parent 33e6b14632
commit aa0a4012be
1 changed files with 1 additions and 1 deletions

View File

@ -502,7 +502,7 @@ func (scope *Scope) addForeignKey(field string, dest string, onDelete string, on
var table = scope.TableName()
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;`
scope.Raw(fmt.Sprintf(query, table, keyName, field, dest, onDelete, onUpdate)).Exec()
scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), keyName, field, dest, onDelete, onUpdate)).Exec()
}
func (scope *Scope) removeIndex(indexName string) {