我有一个表,该表的主键在其他几个表中使用,并且对其他表有几个外键。
CREATE TABLE location ( locationID INT NOT NULL AUTO_INCREMENT PRIMARY KEY ... ) ENGINE = InnoDB; CREATE TABLE assignment ( assignmentID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, locationID INT NOT NULL, FOREIGN KEY locationIDX (locationID) REFERENCES location (locationID) ... ) ENGINE = InnoDB; CREATE TABLE assignmentStuff ( ... assignmentID INT NOT NULL, FOREIGN KEY assignmentIDX (assignmentID) REFERENCES assignment (assignmentID) ) ENGINE = InnoDB;
问题是,当我尝试删除外键列之一(即locationIDX)时,它给了我一个错误。
“错误1025(HY000):重命名错误”
如何在没有出现此错误的情况下将列删除到上面的分配表中?
正如解释在这里,似乎外键约束必须由被丢弃 的约束名称 ,而不是索引名。语法为:
alter table footable drop foreign key fooconstraint