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:

StatementMySQL 8.4.11MariaDB 11.4.13
ALTER TABLE orders DROP INDEX customer_id15531553
The same after SET foreign_key_checks = 01553Runs; the key stays, with no index
DROP PRIMARY KEY when the key’s column leads the primary key1553 on PRIMARY1025, errno 150
DROP INDEX of a UNIQUE key the foreign key uses15531553
ALTER TABLE orders DROP COLUMN customer_id1828, names orders_ibfk_11553 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 wantRunWhat is left
The foreign key and its index goneALTER TABLE orders DROP FOREIGN KEY orders_ibfk_1, DROP INDEX customer_id;Neither
The foreign key kept, on a different indexALTER TABLE orders ADD INDEX orders_customer_created (customer_id, created_at), DROP INDEX customer_id;The key, on the new index
The column goneALTER 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 indexNot 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 orders table's Indexes tab in Schemity, read from MySQL 9.7.4 after both Laravel migrations: one index, orders_customer_id_created_at_index on customer_id and created_at, and no orders_customer_id_foreign index, while the relation from customers to orders is still drawn

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 SQL migration drawer in Schemity on a MySQL 9.7.4 diagram of customers and orders, analysing alter table orders drop index orders_customer_id_created_at_index: 1 object depends on orders.customer_id and the database refuses the change, the foreign key orders_customer_id_foreign

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.

Frequently asked questions

How do I fix MySQL error 1553 Cannot drop index needed in a foreign key constraint?

Decide first whether the foreign key stays. If it goes, run ALTER TABLE orders DROP FOREIGN KEY orders_ibfk_1, DROP INDEX customer_id; so both leave together. If it stays, add an index that starts with the foreign key's columns in the same statement as the drop, for example ALTER TABLE orders ADD INDEX orders_customer_created (customer_id, created_at), DROP INDEX customer_id;.

Does DROP FOREIGN KEY drop the index in MySQL?

No. On MySQL 8.4 and MariaDB 11.4, ALTER TABLE ... DROP FOREIGN KEY removes the constraint and leaves its index in place, including the index MySQL created for the key on its own. Drop it in the same statement with DROP INDEX if nothing else uses it, or keep it if your queries filter on that column.

Does SET foreign_key_checks = 0 let me drop the index?

Not on MySQL. With foreign_key_checks set to 0, MySQL 8.4 still refuses the drop with error 1553, and the MySQL manual lists dropping an index required by a foreign key among the things still checked. MariaDB 11.4 does let it through, and leaves a foreign key that is still enforced but has no index at all.