尝试删除外键时出错:“ERROR 1025(HY000):”

时间:2022-10-14 13:49:12

I am running into some trouble trying to delete a foreign key. Could someone please help?

我在尝试删除外键时遇到了一些麻烦。有人可以帮忙吗?

Here’s my SHOW CREATE TABLE catgroup:

这是我的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\

ERROR 1025(HY000):将“。\ asset_base \ catgroup”重命名为“。\ asset_base”时出错

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

What am I doing wrong?

我究竟做错了什么?

3 个解决方案

#1


7  

You have the wrong name of the foreign key. Try catgroup_ibfk_2 instead.

您的外键名称错误。请尝试catgroup_ibfk_2。

The strange error message is already reported as a bug in MySQL.

奇怪的错误消息已经报告为MySQL中的错误。

#2


2  

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

古代帖子,但FWIW我刚发现外键名称区分大小写......

#3


0  

[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.

更改InnoDB表上的索引/约束涉及删除表并重建它。您可能需要删除指向这些父行的另一个表上的约束,然后才能执行此操作。

#1


7  

You have the wrong name of the foreign key. Try catgroup_ibfk_2 instead.

您的外键名称错误。请尝试catgroup_ibfk_2。

The strange error message is already reported as a bug in MySQL.

奇怪的错误消息已经报告为MySQL中的错误。

#2


2  

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

古代帖子,但FWIW我刚发现外键名称区分大小写......

#3


0  

[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.

更改InnoDB表上的索引/约束涉及删除表并重建它。您可能需要删除指向这些父行的另一个表上的约束,然后才能执行此操作。