开发者

Help with: ERROR 1025 (HY000): Error on rename of .... (errno: 150)

I am getting this error when I am trying to run an alter table command to drop a colum开发者_开发技巧n: 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.


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;


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜