How to fix ERROR 1025: Error on rename in MySQL

MySQLINTERMEDIATEHIGHUpdated Dec 22, 2025ยท 164 views

MySQL ERROR 1025 occurs when attempting to rename or alter a table that has foreign key constraints or other structural conflicts. This error typically stems from constraint violations or file system issues during the rename operation.

Quick fix

Fixes ERROR 1025: Error on rename

SHOW CREATE TABLE your_table_name;
  1. Identify the foreign key constraint causing the issue
  2. Drop the problematic foreign key constraint
  3. Perform your alter table operation
  4. Re-add the foreign key constraint if needed
mysql โ€” error
SHOW CREATE TABLE your_table_name;
ERROR 1025: Error on rename

What this error means

MySQL ERROR 1025 (HY000) is a generic error that MySQL throws when a rename operation on a table or column fails. The error message format "Error on rename of 'x' to 'y' (errno: N)" indicates that MySQL tried to rename a temporary table to your target table name during an ALTER TABLE operation, but failed for a reason indicated by the underlying errno code. The most common errno is 150, which indicates a foreign key constraint conflict.

Typical symptoms

  • Receiving "ERROR 1025 (HY000): Error on rename of '...' to '...'" when running ALTER TABLE or RENAME TABLE
  • ALTER TABLE commands fail when attempting to drop columns or change table structure
  • Foreign key constraint violations during table modifications
  • Table locks preventing rename operations from completing
  • Collation or character set changes triggering the error

Common causes

  1. Foreign key constraints on the column being dropped or the table being altered - the most common cause (errno: 150)
  2. Renaming a column that is referenced by a foreign key constraint in another table
  3. Table locks or in-use tables blocking the rename operation
  4. Incorrect constraint name used in DROP FOREIGN KEY statement (case sensitivity issues)
  5. Data type or collation mismatches between referencing and referenced tables
  6. File system permissions preventing MySQL from renaming the underlying table files
  7. Missing database name qualifier when referencing tables in cross-database operations

How to fix "ERROR 1025: Error on rename"

1Identify the foreign key constraint causing the issue

First, check if the error is related to a foreign key by looking at the errno value. If it shows "errno: 150", it is definitely a foreign key constraint issue.

Get the exact constraint name:

sql
SHOW CREATE TABLE your_table_name;

This will display the table structure including all foreign key constraint names. Look for lines like CONSTRAINT constraint_name FOREIGN KEY.

2Drop the problematic foreign key constraint

Once you have identified the constraint name (be careful with case sensitivity on Linux systems), drop it:

sql
ALTER TABLE your_table_name DROP FOREIGN KEY constraint_name;

Make sure the constraint name matches exactly as shown in SHOW CREATE TABLE output, including proper case sensitivity.

3Perform your alter table operation

Now execute your original ALTER TABLE command that was failing:

sql
ALTER TABLE your_table_name DROP COLUMN column_name;

or

sql
ALTER TABLE your_table_name MODIFY COLUMN column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Replace with your actual operation.

4Re-add the foreign key constraint if needed

After successfully modifying the table, re-add the foreign key constraint:

sql
ALTER TABLE your_table_name ADD CONSTRAINT constraint_name FOREIGN KEY (column_name) REFERENCES referenced_table(referenced_column);

Make sure the column types and collations match between the referencing and referenced tables.

5Check for any remaining warnings

After all operations complete, verify there are no issues:

sql
SHOW WARNINGS;

This will display any warnings from your ALTER TABLE operations that might indicate incomplete constraint updates.

Advanced notes

For MySQL 5.7 and earlier, if standard approaches fail, you can temporarily disable foreign key checks: SET FOREIGN_KEY_CHECKS=0; [perform your operation] SET FOREIGN_KEY_CHECKS=1; However, this should be used carefully and only after backing up your database, as it bypasses referential integrity checks. MySQL 8.0+ provides clearer error messages like "ERROR 1828 (HY000): Cannot drop column '...': needed in a foreign key constraint" that make troubleshooting easier. If using cross-database operations, always qualify table names with the database name: database_name.table_name. Some frameworks like Laravel migrations may encounter this when running migrations with foreign key constraints; ensure the correct --disable-foreign-keys flag is used or wrap operations with SET FOREIGN_KEY_CHECKS commands.

Frequently asked questions

What does "ERROR 1025: Error on rename" mean?
MySQL ERROR 1025 (HY000) is a generic error that MySQL throws when a rename operation on a table or column fails. The error message format "Error on rename of 'x' to 'y' (errno: N)" indicates that MySQL tried to rename a temporary table to your target table name during an ALTER TABLE operation, but failed for a reason indicated by the underlying errno code. The most common errno is 150, which indicates a foreign key constraint conflict.
How do I fix "ERROR 1025: Error on rename"?
MySQL ERROR 1025 occurs when attempting to rename or alter a table that has foreign key constraints or other structural conflicts. This error typically stems from constraint violations or file system issues during the rename operation.
What causes "ERROR 1025: Error on rename"?
Foreign key constraints on the column being dropped or the table being altered - the most common cause (errno: 150) Renaming a column that is referenced by a foreign key constraint in another table Table locks or in-use tables blocking the rename operation
Is the "ERROR 1025: Error on rename" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading