删除外键以解决 MySQL 中的“错误 1025”
当尝试从表中删除外键列时,MySQL 可能会提示错误“ERROR 1025 (HY000): 重命名时出错。”此错误可能是由于用于删除外键的特定语法而引起的。
在提供的代码的上下文中:
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” “赋值”表中,必须指定约束名称,而不是索引名称。删除外键约束的语法为:
ALTER TABLE table_name DROP FOREIGN KEY constraint_name;
在本例中,约束名称为“locationIDX”(如“FOREIGN KEY”子句中指定)。因此,删除外键的正确命令是:
ALTER TABLE assignment DROP FOREIGN KEY locationIDX;
以上是如何解决删除外键时 MySQL 错误 1025?的详细内容。更多信息请关注PHP中文网其他相关文章!