Error when trying to DELETE foreign key: “ERROR 1025 (HY000):”
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) N开发者_JAVA百科OT 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?
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.
Ancient post, but FWIW I just discovered that the foreign key name is case sensitive...
[admin@gold ~]$ perror 152
MySQL error code 152: Cannot delete a parent row
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.
精彩评论