# 1025 - Error renaming './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. He now has a primary key:

PRIMARY KEY (user_id, round_number) 

Where user_id is the foreign key.

I am trying to change it to this:

 PRIMARY KEY (user_id, round_number, created_at) 

I do this in phpmyadmin by clicking 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) 

This is a MySQL database with the InnoDB table engine.

+68
sql mysql phpmyadmin innodb mysql-error-1025
Nov 02 '10 at 17:55
source share
7 answers

Perhaps there is another table with a foreign key referencing the primary key that 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.

+122
Nov 02 '10 at 18:50
source share

As already mentioned, you need to remove the FK first. On Mysql, do the following:

 ALTER TABLE `table_name` DROP FOREIGN KEY `id_name_fk`; ALTER TABLE `table_name` DROP INDEX `id_name_fk`; 
+27
Sep 04 '13 at 21:04 on
source share

For those who get to this question via google ... this error can also occur if you try to rename a field acting as a foreign key.

+20
Jun 20 '13 at 13:03
source share

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

(For PHPMyAdmin users: To remove the FK restrictions in PHPMyAdmin, select the attribute, then click "Relationship View" next to "Print View" in the toolbar below the table structure)

+13
Dec 01 '13 at 5:38
source share

If you are trying to delete a column that is a FOREIGN KEY, you should find a valid name that is not a column name. For example: if I try to delete the server field in the Alarms table, which is the foreign key in the server table.

  • SHOW CREATE TABLE alarm; Find the line CONSTRAINT `server_id_refs_id_34554433` FORIEGN KEY (`server_id`) REFERENCES `server` (`id`) .
  • ALTER TABLE `alarm` DROP FOREIGN KEY `server_id_refs_id_34554433`;
  • ALTER TABLE `alarm` DROP `server_id`

This will remove the foreign key server from the Alarms table.

+3
Nov 18 '14 at 22:45
source share

I had this problem, this is for foreign key

Click Relation View (for example, the image below), then find the name of the field that you want to delete, and in the Foreign key constraint (INNODB) just make the choice a waste! There is no foreign key.

enter image description here

Hope it works!

+3
Feb 29 '16 at 6:37
source share

If you add a foreign key and encounter this error, it may be the value in the child table is not present in the parent table.

Say for a column in which a foreign key is to be added, all values ​​are set to 0, and the value is not available in the table you are referring to.

You can set some value that is in the parent table and then add a foreign key for me.

0
Nov 18 '16 at 7:32
source share



All Articles