Disclosure: I build Schemity, a desktop ERD tool - this post is from our blog and uses it for the examples.
TL;DR: MySQL refuses to drop the last index whose leading columns hold a foreign key's columns, and turning off
foreign_key_checksdoes not change that on MySQL 8.4. If the foreign key is going too, drop it and the index in oneALTER TABLE. If the key stays, add the replacement index in the same statement as the drop. The trap is an index MySQL swapped in for its own without telling you, which turns a routine rollback into error 1553.
MySQL error 1553, Cannot drop index 'customer_id': needed in a foreign key constraint, means the index you are dropping is the last one MySQL can use to enforce a foreign key, and the fix depends on whether that foreign key should survive the migration. If the key is going too, drop both in one statement. If the key stays, put a replacement index in first. On MySQL nothing else gets past it: not foreign_key_checks = 0, and not dropping the column first.
The error shows up most in rollbacks, because the index being dropped was not always the one MySQL was using. Everything below ran on MySQL 8.4.11 and MariaDB 11.4.13 in throwaway containers (the Laravel case also on MySQL 9.7.4), with the same behaviour on both unless a section says otherwise. The starting point is two tables:
CREATE TABLE customers (id BIGINT PRIMARY KEY); CREATE TABLE orders ( id BIGINT PRIMARY KEY, customer_id BIGINT NOT NULL, created_at DATETIME NOT NULL, FOREIGN KEY (customer_id) REFERENCES customers (id) ); Why does MySQL refuse to drop an index a foreign key uses?
MySQL needs an index whose first columns are the foreign key's columns, in the same order, and it will not let the last such index go while the key exists.
The MySQL manual states the rule, and adds that the index "is created on the referencing table automatically if it does not exist." So the orders table above has an index nobody wrote. SHOW CREATE TABLE orders lists it as KEY customer_id (customer_id) beside CONSTRAINT orders_ibfk_1 FOREIGN KEY. The constraint is named orders_ibfk_1 because the CREATE TABLE gave it no name, and the index is named after its first column. Give the constraint a name, as in CONSTRAINT fk_orders_customer FOREIGN KEY ..., and the index takes the same name as the constraint.
Every way of removing that index is refused on MySQL while the key exists:
| Statement | MySQL 8.4.11 | MariaDB 11.4.13 |
|---|---|---|
ALTER TABLE orders DROP INDEX customer_id | 1553 | 1553 |
The same after SET foreign_key_checks = 0 | 1553 | Runs; the key stays, with no index |
DROP PRIMARY KEY when the key's column leads the primary key | 1553 on PRIMARY | 1025, errno 150 |
DROP INDEX of a UNIQUE key the foreign key uses | 1553 | 1553 |
ALTER TABLE orders DROP COLUMN customer_id | 1828, names orders_ibfk_1 | 1553 on the index |
The foreign_key_checks row surprises people, since that setting is the usual escape hatch for foreign key errors. The MySQL manual lists "Dropping an index required by a foreign key constraint" among the operations still checked when it is off. MariaDB is the exception: with checks off it drops the index, and the foreign key goes on rejecting orphan rows with no index behind it, so every delete from customers has to scan orders for matching rows.
The same error comes from the other end of a key too. Dropping the UNIQUE key or primary key that another table's foreign key references is refused with 1553 on both databases, foreign_key_checks = 0 included on MySQL, and the fix there is to drop or move that foreign key first.
PostgreSQL has no such rule. It never creates an index for a foreign key, so on PostgreSQL 18.3 a DROP INDEX of a plain index on the referencing column always runs, and the cost shows up later as slow deletes on the parent table instead.
Which fix should you use for error 1553?
Pick the fix by what should happen to the foreign key: dropped with its index, kept on a new index, or dropped together with its column.
| You want | Run | What is left |
|---|---|---|
| The foreign key and its index gone | ALTER TABLE orders DROP FOREIGN KEY orders_ibfk_1, DROP INDEX customer_id; | Neither |
| The foreign key kept, on a different index | ALTER TABLE orders ADD INDEX orders_customer_created (customer_id, created_at), DROP INDEX customer_id; | The key, on the new index |
| The column gone | ALTER TABLE orders DROP FOREIGN KEY orders_ibfk_1, DROP COLUMN customer_id; | Neither; the index goes with the column |
| The foreign key kept with no index | Not possible on MySQL |
Order is the whole fix. Split into two statements, the drop has to come second: DROP INDEX before DROP FOREIGN KEY fails with 1553, and so does dropping the old index before the new one exists. One ALTER TABLE takes the order question away, because MySQL checks the table as the whole statement leaves it.
The first row is also the answer to a smaller question: DROP FOREIGN KEY on its own leaves the index behind. After ALTER TABLE orders DROP FOREIGN KEY orders_ibfk_1, the customer_id index is still there, both on MySQL and on MariaDB. Whether to drop it is a real choice. Keep it if your queries filter orders by customer. Drop it if nothing reads by that column, because every insert still pays to maintain it.
Why does a rollback hit error 1553 when the migration ran fine?
Because MySQL silently drops the index it created for a foreign key as soon as you add another index that can do the same job, so the index your rollback removes is now the one the key depends on.
The manual says so in one sentence: the automatic index "might be silently dropped later if you create another index that can be used to enforce the foreign key constraint." Here is how that plays out in a Laravel app. The first migration uses $table->foreignId('customer_id')->constrained(), which Laravel's MySQL grammar writes as a separate statement after the CREATE TABLE:
alter table `orders` add constraint `orders_customer_id_foreign` foreign key (`customer_id`) references `customers` (`id`); MySQL creates an index for it, named orders_customer_id_foreign after the constraint. A later migration adds a composite index for a dashboard query, $table->index(['customer_id', 'created_at']):
alter table `orders` add index `orders_customer_id_created_at_index`(`customer_id`, `created_at`); Run SHOW INDEX FROM orders after that and orders_customer_id_foreign is gone. The composite index starts with customer_id, so MySQL dropped its own index without a warning, and the composite one now enforces the key. Then someone rolls the second migration back. Laravel runs dropIndex(['customer_id', 'created_at']), which is alter table orders drop index orders_customer_id_created_at_index, and MySQL refuses it with error 1553. The migration that created the index ran cleanly, and nothing in the repository says another index was dropped along the way.
The fix for the down method is the pattern of the second row of the table: put a single-column index back in the same statement as the drop.
alter table `orders` add index `orders_customer_id_index`(`customer_id`), drop index `orders_customer_id_created_at_index`; In Laravel that is $table->index('customer_id'); before $table->dropIndex(['customer_id', 'created_at']); in the down method. Laravel sends them as two statements in that order, which also works: the new index exists by the time the old one is dropped. Only an index MySQL made on its own is replaced this way. An index you created yourself, even one with the same columns, stays when you add the composite one, and with two indexes that both start with customer_id, either one can be dropped.
How does Schemity catch an index drop MySQL will refuse?
Schemity is database design software that reads your live database, shows the impact of every schema change before it runs, and keeps the diagram as a file in Git. Writing this post found that its impact analysis missed this error, and the fixes described here ship in the next release. To see the impact of every change before it reaches production, impact analysis (a Schemity Pro feature) reads the indexes and foreign keys of the connected MySQL or MariaDB database. It reports a drop of the last index that a foreign key's columns lead as refused, and names the foreign key. That covers a plain index, a UNIQUE key and the primary key, and on the other end of the key, the UNIQUE or primary key another table's foreign key references. It works whether the drop comes from an edit on the diagram or from a migration file pasted into the SQL migration drawer (Shift+F7).
On a diagram connected to the Laravel database above, after both migrations, the rollback's SQL from php artisan migrate:rollback --pretend reports orders_customer_id_foreign as refusing the drop. Pasting the corrected down method's SQL reports nothing. A DROP FOREIGN KEY earlier in the same file or statement is taken into account too, so dropping both together is not flagged. Schemity reads MySQL's own spelling of these statements, DROP INDEX, DROP KEY and DROP FOREIGN KEY inside ALTER TABLE, and ADD INDEX as Laravel writes it. A DROP INDEX whose name is also a foreign key's name drops the index, never the key.
The same engine runs with no database in Migration Check in CI, which is free. There it rebuilds the schema from the older migrations and assumes MySQL's own index for a foreign key that no other index covers. With the next release, the Laravel rollback above is reported as refused in a pull request too, before anyone runs it. One case is still missed: when a foreign key was created without a name, MySQL names its index after the column, and a live database does not say that MySQL created it. A single file that adds a composite index on such a table and later drops it again is then not flagged, because Schemity cannot know MySQL replaced its own index in between.
Related reading
- MySQL ALTER TABLE: which changes lock the table covers what each of these statements costs on a large table.
- Transactional DDL in PostgreSQL, MySQL and CockroachDB explains why a failed MySQL migration leaves its earlier statements applied.
- Laravel ERD from migrations or the database shows why the live database is the better source for a Laravel schema diagram.


