Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#1025 - Error on rename of './database/#sql-2e0f_1254ba7' to './database/table' (errno: 150)

So I am trying to add a primary key to one of the tables in my database. Right now it has a primary key like this:

PRIMARY KEY (user_id, round_number)

Where user_id is a foreign key.

I am trying to change it to this:

PRIMARY KEY (user_id, round_number, created_at)

I am doing this in phpmyadmin by clicking on the primary key icon in the table structure view.

This is the error I get:

#1025 - Error on rename of './database/#sql-2e0f_1254ba7' to './database/table' (errno: 150)

It is a MySQL database with InnoDB table engine.

like image 347
Richard Knop Avatar asked Nov 02 '10 17:11

Richard Knop


4 Answers

There is probably another table with a foreign key referencing the primary key you are trying to change.

To find out which table caused the error you can run SHOW ENGINE INNODB STATUS and then look at the LATEST FOREIGN KEY ERROR section.

like image 50
Ike Walker Avatar answered Nov 13 '22 04:11

Ike Walker


As was said you need to remove the FKs before. On Mysql do it like this:

ALTER TABLE `table_name` DROP FOREIGN KEY `id_name_fk`;

ALTER TABLE `table_name` DROP INDEX `id_name_fk`;
like image 40
Wellington Lorindo Avatar answered Nov 13 '22 04:11

Wellington Lorindo


For those who are getting to this question via google... this error can also happen if you try to rename a field that is acting as a foreign key.

like image 24
Dave C Avatar answered Nov 13 '22 03:11

Dave C


To bypass this in PHPMyAdmin or with MySQL, first remove the foreign key constraint before renaming the attribute.

(For PHPMyAdmin users: To remove FK constrains in PHPMyAdmin, select the attribute then click "relation view" next to "print view" in the toolbar below the table structure)

like image 13
LazerSharks Avatar answered Nov 13 '22 03:11

LazerSharks