What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

Questions : What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

802

I tried this in mysql:

mysql> alter table region drop column country_id; 

And got this:

ERROR 1025 (HY000): Error on rename of './product/#sql-14ae_81' to './product/region' (errno: 150) 

Any ideas? Foreign key stuff?

Total Answers 14
25

Answers 1 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

You usually get this error if your in4codes_mysql-error-1025 tables use the InnoDB engine. In that in4codes_mysql-error-1025 case you would have to drop the foreign in4codes_mysql-error-1025 key, and then do the alter table and in4codes_mysql-error-1025 drop the column.

But the tricky part is that you can’t in4codes_mysql-error-1025 drop the foreign key using the column in4codes_mysql-error-1025 name, but instead you would have to find in4codes_mysql-error-1025 the name used to index it. To find that, in4codes_mysql-error-1025 issue the following select:

SHOW CREATE TABLE region;

This should show you the name of the in4codes_mysql-error-1025 index, something like this:

CONSTRAINT region_ibfk_1 FOREIGN KEY in4codes_mysql-error-1025 (country_id) REFERENCES country (id) in4codes_mysql-error-1025 ON DELETE NO ACTION ON UPDATE NO in4codes_mysql-error-1025 ACTION

Now simply issue an:

alter table region drop foreign key in4codes_mysql-error-1025 region_ibfk_1;

And finally an:

alter table region drop column in4codes_mysql-error-1025 country_id;

And you are good to go!

0

2

Answers 2 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

It is indeed a foreign key error, you in4codes_mysql-error-1025 can find out using perror:

shell$ perror 150 MySQL error code 150: Foreign key constraint is incorrectly formed 

To find out more details about what in4codes_mysql-error-1025 failed, you can use SHOW ENGINE INNODB in4codes_mysql-error-1025 STATUS and look for the LATEST FOREIGN in4codes_mysql-error-1025 KEY ERROR section it contains details in4codes_mysql-error-1025 about what is wrong.

In your case, it is most likely cause in4codes_mysql-error-1025 something is referencing the country_id in4codes_mysql-error-1025 column.

0

6

Answers 3 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

You can get also get this error trying in4codes_mysql-error-1025 to drop a non-existing foreign key. So in4codes_mysql-error-1025 when dropping foreign keys, always make in4codes_mysql-error-1025 sure they actually exist.

If the foreign key does exist, and you in4codes_mysql-error-1025 are still getting this error try the in4codes_mysql-error-1025 following:

SET @OLD[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD[email protected]@SQL_MODE, SQL_MODE='TRADITIONAL'; 

// Drop the foreign key here!

SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; 

This always does the trick for me 🙂

0

2

Answers 4 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

Simply run the alter table query using in4codes_mysql-error-1025 ‘KEY’ instead of ‘FOREIGN KEY’ in the in4codes_mysql-error-1025 drop statement. I hope it will help to in4codes_mysql-error-1025 solve the issue, and will drop the in4codes_mysql-error-1025 foreign key constraint and you can in4codes_mysql-error-1025 change the table columns and drop the in4codes_mysql-error-1025 table.

ALTER TABLE slide_image_sub DROP KEY FK_slide_image_sub; 

here in DROP KEY instead of DROP FOREIGN in4codes_mysql-error-1025 KEY,

hope it will help.

Thanks

0

4

Answers 5 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

I know, this is an old post, but it’s in4codes_mysql-error-1025 the first hit on everyone’s favorite in4codes_mysql-error-1025 search engine if you are looking for in4codes_mysql-error-1025 error 1025.

However, there is an easy “hack” for in4codes_mysql-error-1025 fixing this issue:

Before you execute your command(s) you in4codes_mysql-error-1025 first have to disable the foreign key in4codes_mysql-error-1025 constraints check using this command:

SET FOREIGN_KEY_CHECKS = 0; 

Then you are able to execute your in4codes_mysql-error-1025 command(s).

After you are done, don’t forget to in4codes_mysql-error-1025 enable the foreign key constraints check in4codes_mysql-error-1025 again, using this command:

SET FOREIGN_KEY_CHECKS = 1; 

Good luck with your endeavor.

0

1

Answers 6 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

I had a similar issues once. I deleted in4codes_mysql-error-1025 the primary key from TABLE A but when I in4codes_mysql-error-1025 was trying to delete the foreign key in4codes_mysql-error-1025 column from table B I was shown the in4codes_mysql-error-1025 above same error.

You can’t drop the foreign key using the in4codes_mysql-error-1025 column name and to bypass this in in4codes_mysql-error-1025 PHPMyAdmin or with MySQL, first remove in4codes_mysql-error-1025 the foreign key constraint before in4codes_mysql-error-1025 renaming or deleting the attribute.

0

2

Answers 7 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

Take a look in error file for your mysql in4codes_mysql-error-1025 database. According to Bug #26305 my sql in4codes_mysql-error-1025 do not give you the cause. This bug in4codes_mysql-error-1025 exists since MySQL 4.1 😉

0

5

Answers 8 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

If you are using a client like MySQL in4codes_mysql-error-1025 Workbench, right click the desired table in4codes_mysql-error-1025 from where a foreign key is to be in4codes_mysql-error-1025 deleted, then select the foreign key tab in4codes_mysql-error-1025 and delete the indexes.

Then you can run the query like this:

alter table table_name drop foreign_key_col_name; 

0

1

Answers 9 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

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

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

Use SHOW CREATE TABLE categories to show in4codes_mysql-error-1025 the name of constraint.

Most probably it will be in4codes_mysql-error-1025 categories_ibfk_1

Use the name to drop the foreign key in4codes_mysql-error-1025 first and the column then:

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

0

4

Answers 10 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

I got this error with MySQL 5.6 but it in4codes_mysql-error-1025 had nothing to do with Foreign keys. in4codes_mysql-error-1025 This was on a Windows 7 Professional in4codes_mysql-error-1025 machine acting as a server on a small in4codes_mysql-error-1025 LAN.

The client application was doing a batch in4codes_mysql-error-1025 operation that creates a table fills it in4codes_mysql-error-1025 with some external data then runs a in4codes_mysql-error-1025 query joining with permanent tables then in4codes_mysql-error-1025 dropping the “temporary” table. This in4codes_mysql-error-1025 batch does this approximately 300 times in4codes_mysql-error-1025 and this particular routine had been in4codes_mysql-error-1025 running week in week out for several in4codes_mysql-error-1025 years when suddenly we get the Error in4codes_mysql-error-1025 1025 Unable to rename problem at a in4codes_mysql-error-1025 random point in the batch.

In my case the application was using 4 in4codes_mysql-error-1025 DDL statements a CREATE TABLE followed in4codes_mysql-error-1025 by 3 CREATE INDEX, there is no foreign in4codes_mysql-error-1025 key. However only 2 of the indexes in4codes_mysql-error-1025 actually get created and the actual in4codes_mysql-error-1025 table .frm file was renamed, at the in4codes_mysql-error-1025 point of failure.

My solution was to get rid of the in4codes_mysql-error-1025 separate CREATE INDEX statements and in4codes_mysql-error-1025 create them using the CREATE TABLE in4codes_mysql-error-1025 statement. This at the time of writing in4codes_mysql-error-1025 has solved the issue for me and my help in4codes_mysql-error-1025 someone else scratching their head when in4codes_mysql-error-1025 they find this thread.

0

3

Answers 11 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

I’d guess foreign key constraint in4codes_mysql-error-1025 problem. Is country_id used as a in4codes_mysql-error-1025 foreign key in another table?

I’m not DB guru but I think I solved a in4codes_mysql-error-1025 problem like this (where there was a fk in4codes_mysql-error-1025 constraint) by removing the fk, doing my in4codes_mysql-error-1025 alter table stuff and then redoing the in4codes_mysql-error-1025 fk stuff.

I’ll be interested to hear what the in4codes_mysql-error-1025 outcome is – sometime mysql is pretty in4codes_mysql-error-1025 cryptic.

0

3

Answers 12 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

In my case, I was using MySQL workbench in4codes_mysql-error-1025 and I faced the same issue while in4codes_mysql-error-1025 dropping one of my columns in a table. I in4codes_mysql-error-1025 could not find the name of the foreign in4codes_mysql-error-1025 key. I followed the following steps to in4codes_mysql-error-1025 resolve the issue:

  1. Rt. click on your schema and select in4codes_mysql-error-1025 ‘schema inspector’. This gives you in4codes_mysql-error-1025 various tables, columns, indexes, ect.

  2. Go to the tab named ‘Indexes’ and search in4codes_mysql-error-1025 the name of the column under the column in4codes_mysql-error-1025 named ‘Column’. Once found check the in4codes_mysql-error-1025 name of the table for this record under in4codes_mysql-error-1025 the column name ‘Table’. If it matches in4codes_mysql-error-1025 the name of the table you want, then in4codes_mysql-error-1025 note down the name of the foreign key in4codes_mysql-error-1025 from the column named ‘Name’.

  3. Now execute the query : ALTER table in4codes_mysql-error-1025 tableNamexx DROP KEY foreignKeyName;

  4. Now you can execute the drop statement in4codes_mysql-error-1025 which shall execute successfully.

0

3

Answers 13 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

Doing

SET FOREIGN_KEY_CHECKS=0; 

before the Operation can also do the in4codes_mysql-error-1025 trick.

0

2

Answers 14 : of What does mysql error 1025 (HY000): Error on rename of .foo (errorno: 150) mean

averageRatings= FOREACH groupedRatings in4codes_mysql-error-1025 GENERATE group AS movieID, in4codes_mysql-error-1025 AVG(ratings.rating) AS avgRating, in4codes_mysql-error-1025 COUNT(ratings.rating) AS numRatings;

If you are using any command like above in4codes_mysql-error-1025 you must use group in small letters. in4codes_mysql-error-1025 This may solve your problem it solved in4codes_mysql-error-1025 mine. At least in PIG script.

0