尝试删除列会产生错误 1025 (HY000): 重命名...时出错 (errno: 150)

发布于 2024-11-06 07:39:11 字数 610 浏览 0 评论 0原文

我正在尝试运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻之岛 2024-11-13 07:39:11

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

最有可能的是 categories_ibfk_1

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

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

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:

ALTER TABLE categories DROP FOREIGN KEY categories_ibfk_1;
ALTER TABLE categories DROP COLUMN assets_id;
凉月流沐 2024-11-13 07:39:11

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

每个人(意外地)都可以访问该网站。所以更新脚本被启动了多次。这导致了竞争条件,引发了这样的错误。

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

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文