尝试删除外键时出错:“ERROR 1025 (HY000):”
我在尝试删除外键时遇到了一些麻烦。有人可以帮忙吗?
这是我的 SHOW CREATE TABLE catgroup:
| catgroup | CREATE TABLE `catgroup` (
`catgroupid` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
PRIMARY KEY (`catgroupid`),
KEY `category_id` (`category_id`),
KEY `group_id` (`group_id`),
CONSTRAINT `catgroup_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `cat
s` (`cid`) ON UPDATE CASCADE,
CONSTRAINT `catgroup_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups
d`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 |
这就是我尝试删除外键的方式:
ALTER TABLE catgroup DROP FOREIGN KEY group_id_ibfk_2;
这是错误消息:
错误 1025 (HY000):将“.\asset_base\catgroup”重命名为时出错 '.\asset_base\
sql2-16b4-4'(错误号:152)
我做错了什么?
I am running into some trouble trying to delete a foreign key. Could someone please help?
Here’s my SHOW CREATE TABLE catgroup:
| catgroup | CREATE TABLE `catgroup` (
`catgroupid` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
PRIMARY KEY (`catgroupid`),
KEY `category_id` (`category_id`),
KEY `group_id` (`group_id`),
CONSTRAINT `catgroup_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `cat
s` (`cid`) ON UPDATE CASCADE,
CONSTRAINT `catgroup_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups
d`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 |
This is how I am trying to drop the foreign key:
ALTER TABLE catgroup DROP FOREIGN KEY group_id_ibfk_2;
And here’s the error message:
ERROR 1025 (HY000): Error on rename of '.\asset_base\catgroup' to
'.\asset_base\sql2-16b4-4' (errno: 152)
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的外键名称错误。请尝试使用
catgroup_ibfk_2
。这个奇怪的错误消息已经被报告为 MySQL 中的错误。
You have the wrong name of the foreign key. Try
catgroup_ibfk_2
instead.The strange error message is already reported as a bug in MySQL.
古老的帖子,但FWIW我刚刚发现外键名称区分大小写......
Ancient post, but FWIW I just discovered that the foreign key name is case sensitive...
更改 InnoDB 表上的索引/约束涉及删除表并重建它。您可能需要先删除指向这些父行的另一个表上的约束,然后才能执行此操作。
Altering indexes/constraints on an InnoDB table involves dropping the table and rebuilding it. You probably need to remove the constraint on the other table pointing to these parent rows before you can do that.