MySQL 帮助:ERROR 1025 (HY000): Error on rename of .... (errno: 150)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5948704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Help with: ERROR 1025 (HY000): Error on rename of .... (errno: 150)
提问by Henkka
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).
当我尝试运行更改表命令删除列时出现此错误:ERROR 1025 (HY000): Error on rename of .... (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 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.
表类别是完全空白的。所以没有任何信息来触发 CASCADE 限制。那么你能帮我删除列assets_id需要什么样的魔法吗?谢谢你。
回答by Quassnoi
Use SHOW CREATE TABLE categories
to show the name of constraint.
使用SHOW CREATE TABLE categories
显示约束的名称。
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;
回答by Rabbit
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.
每个人都可以(意外地)访问该站点。所以更新脚本被多次启动。这导致了引发此类错误的竞争条件。
-> Be sure that the site gets accessed only once, until every script finished!
-> 确保该站点仅被访问一次,直到每个脚本完成!