An error occurred while trying to DELETE a foreign key: "ERROR 1025 (HY000):"

I'm having trouble deleting a foreign key. Can anybody help?

Heres 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 try to delete the foreign key:

 ALTER TABLE catgroup DROP FOREIGN KEY group_id_ibfk_2; 

And the error message appears:

ERROR 1025 (HY000): Error renaming '. \ Asset_base \ catgroup' to. \ Asset_base \

sql2-16b4-4 '(errno: 152)

What am I doing wrong?

+8
mysql foreign-keys
source share
3 answers

You have an invalid foreign key name. Instead, try catgroup_ibfk_2 .

A strange error message is already reported as an error in MySQL .

+7
source share

Ancient record, but FWIW I just discovered that the foreign key name is case sensitive ...

+2
source share
 [admin@gold ~]$ perror 152 MySQL error code 152: Cannot delete a parent row 

Changing indexes / constraints on an InnoDB table includes deleting the table and restoring it. You probably need to remove the restriction on another table pointing to these parent rows before you can do this.

0
source share

All Articles