尝试删除列会产生错误 1025 (HY000): 重命名...时出错 (errno: 150)
我正在尝试运行 alter table 命令来删除列:
ERROR 1025 (HY000): Error on rename of .... (errno: 150).
如果我理解正确,这是一个外键问题,但我不知道如何修复它。有人会这么好心告诉我如何让它工作吗?
用于创建表的代码:
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;
alter 命令:
ALTER TABLE categories DROP COLUMN assets_id;
表类别完全空白。所以没有信息可以掀起CASCADE限制。
如何删除 asset_id 列?
I am trying to run an alter table command to drop a column:
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.
How can I delete the column assets_id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
SHOW CREATE TABLEcategories
来显示约束的名称。最有可能的是
categories_ibfk_1
使用名称首先删除外键,然后删除列:
Use
SHOW CREATE TABLE categories
to show the name of constraint.Most probably it will be
categories_ibfk_1
Use the name to drop the foreign key first and the column then:
对我来说,问题是另一个问题:
每个人(意外地)都可以访问该网站。所以更新脚本被启动了多次。这导致了竞争条件,引发了这样的错误。
->确保该站点仅被访问一次,直到每个脚本完成!
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!