Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

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).

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.

like image 754
Henkka Avatar asked May 10 '11 10:05

Henkka


1 Answers

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; 
like image 169
Quassnoi Avatar answered Oct 02 '22 15:10

Quassnoi