Help with: ERROR 1025 (HY000):重命名的错误(errno: 150)

时间:2022-10-14 13:34:59

I am getting this error when I am trying to run an alter table command to drop a column: ERROR 1025 (HY000): Error on rename of .... (errno: 150).

我得到这个错误当我试图运行alter table命令将一个列:错误1025(HY000):错误的重命名....(errno:150)。

If I understand correctly it is a foreign key problem, but I do not have a clue how to fix it. Would somebody be so kind and tell me how to get it working.

如果我理解正确,这是一个国外的关键问题,但我不知道如何解决它。会不会有人这么善良,告诉我如何让它发挥作用。

The code used for creating table:

用于创建表的代码:

CREATE TABLE categories(
cid INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
assets_id INT NOT NULL,
cat_name VARCHAR(30) NOT NULL,
INDEX(assets_id),
FOREIGN KEY (assets_id) REFERENCES asset(aid) ON UPDATE CASCADE

)
ENGINE=INNODB DEFAULT CHARSET=utf8;

The alter command:

alter命令:

ALTER TABLE categories DROP COLUMN assets_id;

The table categories is completely blank. So there is no information to set off the CASCADE restrictions. So could you help me what kind of wizardry do I need to delete the column assets_id. Thank you.

表类别是完全空白的。所以没有信息可以触发级联限制。你能帮我删除阿塞_id列吗?谢谢你!

2 个解决方案

#1


68  

Use SHOW CREATE TABLE categories to show the name of constraint.

使用SHOW CREATE TABLE category来显示约束的名称。

Most probably it will be categories_ibfk_1

很可能是categories_ibfk_1

Use the name to drop the foreign key first and the column then:

使用名称先删除外键,然后删除列:

ALTER TABLE categories DROP FOREIGN KEY categories_ibfk_1;
ALTER TABLE categories DROP COLUMN assets_id;

#2


0  

For me the problem was a different one:

对我来说,问题是另一个问题:

The site was (accidentally) accessible for everyone. So the update script was startet multiple times. That caused race conditions that threw errors like this.

这个网站(意外地)人人都能访问。所以更新脚本多次是startet。这导致了像这样的比赛情况。

-> Be sure that the site gets accessed only once, until every script finished!

->确保网站只被访问一次,直到每个脚本完成!

#1


68  

Use SHOW CREATE TABLE categories to show the name of constraint.

使用SHOW CREATE TABLE category来显示约束的名称。

Most probably it will be categories_ibfk_1

很可能是categories_ibfk_1

Use the name to drop the foreign key first and the column then:

使用名称先删除外键,然后删除列:

ALTER TABLE categories DROP FOREIGN KEY categories_ibfk_1;
ALTER TABLE categories DROP COLUMN assets_id;

#2


0  

For me the problem was a different one:

对我来说,问题是另一个问题:

The site was (accidentally) accessible for everyone. So the update script was startet multiple times. That caused race conditions that threw errors like this.

这个网站(意外地)人人都能访问。所以更新脚本多次是startet。这导致了像这样的比赛情况。

-> Be sure that the site gets accessed only once, until every script finished!

->确保网站只被访问一次,直到每个脚本完成!