MySQL "Cannot drop index needed in a foreign key constraint" (error 1553)
Codemia Knowledge Hub ·
MySQL error 1553 ("Cannot drop index 'index_name': needed in a foreign key constraint") means the index you are dropping is the one MySQL uses to enforce a foreign key. MySQL requires an index on the foreign key columns of both parent and child tables, so it blocks the drop to protect referential integrity. Drop the foreign key constraint first, then the index, and recreate the constraint afterward if you still need it.
Why MySQL needs an index for every foreign key
PostgreSQL can enforce foreign keys without a dedicated index (though it recommends one for performance). MySQL's InnoDB engine requires an index on the referencing columns. When you create a foreign key, InnoDB creates an index on the child table's foreign key columns if none exists, and uses it to check constraint violations efficiently on inserts, updates and deletes.
The parent table's referenced columns must also be indexed. Usually that is the primary key, but any unique index works.
Here idx_orders_customer_id supports the foreign key fk_orders_customer, so dropping it triggers error 1553.
Reproducing the error
Removing the index would leave the constraint without the index it needs.
Fixing it step by step
Step 1: Find the foreign key constraint
Find which foreign keys depend on the index with INFORMATION_SCHEMA:
This returns the constraint name (e.g., fk_orders_customer) you need next.
For a quick view, use SHOW CREATE TABLE:
The output lists all constraints and indexes, so you can see which index belongs to which foreign key.
Step 2: Drop the foreign key constraint
This removes the constraint but leaves the index. MySQL does not drop the index automatically.
Step 3: Drop the index
The index is no longer required by any constraint:
Step 4: Recreate the foreign key (if needed)
If you still need referential integrity and only wanted to replace the index (for example, with a composite index), recreate the constraint:
MySQL uses the new composite index for the foreign key as long as the foreign key columns are a leftmost prefix of the index.
Doing it in a single ALTER TABLE
Combining the operations in one ALTER TABLE lets MySQL process the table in a single operation:
The new constraint needs a different name: reusing fk_orders_customer in the same statement that drops it fails with ERROR 1826 (duplicate foreign key constraint name).
On large tables this reduces downtime, since InnoDB handles one table operation instead of four separate ones. Adding a foreign key with foreign_key_checks on still uses the table-copy algorithm, so expect that part to take time.
FOREIGN_KEY_CHECKS does not get around it
Disabling foreign key checks looks like a shortcut, but MySQL 8.0 still refuses the drop:
FOREIGN_KEY_CHECKS skips row-level checks on inserts, updates and deletes; it does not let an index that backs a constraint disappear. Drop the foreign key first, as shown above.
Listing every foreign key in a database
When refactoring indexes across many tables, see all foreign key relationships at once:
This maps every foreign key, its columns and its cascade rules, which you need before changing indexes.
Which indexes can back a foreign key
| Rule | Example | Supported? |
| Exact match on FK columns | INDEX (customer_id) for FK on customer_id | Yes |
| Leftmost prefix of composite index | INDEX (customer_id, order_date) for FK on customer_id | Yes |
| Non-leftmost column of composite index | INDEX (order_date, customer_id) for FK on customer_id | No |
| Unique index | UNIQUE (customer_id) for FK on customer_id | Yes |
| Primary key | PRIMARY KEY (customer_id) for FK on customer_id | Yes |
A composite index satisfies a foreign key only if the FK columns are a leftmost prefix: INDEX (a, b) works for a foreign key on (a) but not on (b).
Mistakes when dropping foreign key indexes
Dropping the index before the foreign key. MySQL enforces the order strictly. Drop the foreign key first, or combine both in one ALTER TABLE.
Expecting MySQL to drop the index with the foreign key. It doesn't. The auto-created index stays and must be removed separately if you no longer need it.
Leaving FOREIGN_KEY_CHECKS = 0 on. The setting is session-scoped, so other sessions are unaffected, but data inserted during that session is not validated.
Not checking which index the foreign key uses. With several candidate indexes (e.g., INDEX (customer_id) and INDEX (customer_id, status)), MySQL uses one of them. Dropping the other may succeed while dropping the chosen one triggers the error. SHOW CREATE TABLE shows which is associated with the constraint.
Forgetting cascade rules when recreating. Specify ON DELETE and ON UPDATE again. The default is RESTRICT, which may differ from the original constraint.
Related reading
- MySQL Can't create table errno 150
- MySQL case sensitive query
- mysql CHANGE MASTER TO command's MASTER_HOST's length limitation
- mysql check collation of a table
- MySQL Cloning a MySQL database on the same MySql instance
- MySQL combine two columns into one column
- mysql command for showing current configuration variables
- Mysql command not found in OS X 10.7
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.