mirror of https://github.com/go-gorm/gorm.git
Fixed mysql query syntax for FK removal (#1993)
This commit is contained in:
parent
d68403b29d
commit
409121d9e3
10
scope.go
10
scope.go
|
@ -1216,11 +1216,17 @@ func (scope *Scope) addForeignKey(field string, dest string, onDelete string, on
|
||||||
|
|
||||||
func (scope *Scope) removeForeignKey(field string, dest string) {
|
func (scope *Scope) removeForeignKey(field string, dest string) {
|
||||||
keyName := scope.Dialect().BuildKeyName(scope.TableName(), field, dest, "foreign")
|
keyName := scope.Dialect().BuildKeyName(scope.TableName(), field, dest, "foreign")
|
||||||
|
|
||||||
if !scope.Dialect().HasForeignKey(scope.TableName(), keyName) {
|
if !scope.Dialect().HasForeignKey(scope.TableName(), keyName) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var query = `ALTER TABLE %s DROP CONSTRAINT %s;`
|
var mysql mysql
|
||||||
|
var query string
|
||||||
|
if scope.Dialect().GetName() == mysql.GetName() {
|
||||||
|
query = `ALTER TABLE %s DROP FOREIGN KEY %s;`
|
||||||
|
} else {
|
||||||
|
query = `ALTER TABLE %s DROP CONSTRAINT %s;`
|
||||||
|
}
|
||||||
|
|
||||||
scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.quoteIfPossible(keyName))).Exec()
|
scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.quoteIfPossible(keyName))).Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue