From aa0a4012be7f21454efbfe42ab22fcf9caf44d5b Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 28 Feb 2015 09:25:05 +0800 Subject: [PATCH] Escaping table names when AddForeignKey --- scope_private.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scope_private.go b/scope_private.go index e831bf4f..c69149c8 100644 --- a/scope_private.go +++ b/scope_private.go @@ -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) {