MySQL 8.4Lab-verified · 2026-11-29

MySQL ERROR 3730 (HY000): Cannot drop table referenced by a foreign key constraint

Another table still has a foreign key pointing at the table you are dropping.

MySQL 8.4.13
3730 (HY000): Cannot drop table 'customers' referenced by a foreign key constraint 'fk_orders_customer' on table 'orders'.

Jump to a cause

  1. 01Dropping a parent table while a child table still references it
  2. 02A cleanup or re-create script drops the parent before the child
  3. 03A table in another database references the table

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4

The message gives everything you need: the table you tried to drop, the constraint name and the child table that holds it, for example Cannot drop table 'customers' referenced by a foreign key constraint 'fk_orders_customer' on table 'orders'.

On MySQL 8.0 and later, dropping a parent table raises 3730 (older versions raised 1217 or 1451 for this). MySQL 8.4 returns the message in English even when lc_messages is Korean or Japanese.

01Dropping a parent table while a child table still references it

orders.customer_id has a foreign key to customers, so DROP TABLE customers is refused even though there are no rows. The check is on the constraint, not the data.

Setup
Setuprun as lab_a
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(50));
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers (id));
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.01 sec)
Reproducerun as lab_a
DROP TABLE customers;
✕ ERROR
ERROR 3730 (HY000): Cannot drop table 'customers' referenced by a foreign key constraint 'fk_orders_customer' on table 'orders'.
Checkrun as lab_a
SELECT table_name, constraint_name FROM information_schema.referential_constraints WHERE constraint_schema = 'lab_a' AND referenced_table_name = 'customers';
OUTPUT
+------------+--------------------+
| TABLE_NAME | CONSTRAINT_NAME    |
+------------+--------------------+
| orders     | fk_orders_customer |
+------------+--------------------+
1 row in set (0.00 sec)
Fixrun as lab_a
ALTER TABLE orders DROP FOREIGN KEY fk_orders_customer;
OUTPUT
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

Find the referencing constraints in information_schema.referential_constraints, drop the foreign key with ALTER TABLE orders DROP FOREIGN KEY fk_orders_customer, then drop the parent. orders stays and only customers is gone.

After the fixrun as lab_a
DROP TABLE customers;
SHOW TABLES;
✓ SUCCESS
Query OK, 0 rows affected (0.01 sec)

+-----------------+
| Tables_in_lab_a |
+-----------------+
| orders          |
+-----------------+
1 row in set (0.00 sec)

02A cleanup or re-create script drops the parent before the child

DROP TABLE IF EXISTS orders fails because order_lines still exists and references it. IF EXISTS only skips missing tables; it does not skip foreign key checks.

Setup
Setuprun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY);
CREATE TABLE order_lines (id INT PRIMARY KEY, order_id INT, CONSTRAINT fk_lines_order FOREIGN KEY (order_id) REFERENCES orders (id));
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)
Reproducerun as lab_a
DROP TABLE IF EXISTS orders;
✕ ERROR
ERROR 3730 (HY000): Cannot drop table 'orders' referenced by a foreign key constraint 'fk_lines_order' on table 'order_lines'.
Checkrun as lab_a
SELECT table_name, constraint_name, referenced_table_name FROM information_schema.referential_constraints WHERE constraint_schema = 'lab_a';
OUTPUT
+-------------+-----------------+-----------------------+
| TABLE_NAME  | CONSTRAINT_NAME | REFERENCED_TABLE_NAME |
+-------------+-----------------+-----------------------+
| order_lines | fk_lines_order  | orders                |
+-------------+-----------------+-----------------------+
1 row in set (0.00 sec)

Drop the child first, or list both tables in one statement: DROP TABLE IF EXISTS order_lines, orders. Both are dropped and SHOW TABLES returns an empty set.

After the fixrun as lab_a
DROP TABLE IF EXISTS order_lines, orders;
SHOW TABLES;
✓ SUCCESS
Query OK, 0 rows affected (0.02 sec)

Empty set (0.00 sec)

03A table in another database references the table

Dropping shop.stock and shop.products together still fails: the message names fk_sales_product on table sales, which lives in the report database. The message does not show the database name, so it is easy to miss.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE TABLE shop.products (id INT PRIMARY KEY);
CREATE TABLE shop.stock (id INT PRIMARY KEY, product_id INT, CONSTRAINT fk_stock_product FOREIGN KEY (product_id) REFERENCES shop.products (id));
CREATE DATABASE report;
CREATE TABLE report.sales (id INT PRIMARY KEY, product_id INT, CONSTRAINT fk_sales_product FOREIGN KEY (product_id) REFERENCES shop.products (id));
OUTPUT
Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.02 sec)
Reproducerun as root
DROP TABLE shop.stock, shop.products;
✕ ERROR
ERROR 3730 (HY000): Cannot drop table 'products' referenced by a foreign key constraint 'fk_sales_product' on table 'sales'.
Checkrun as root
SELECT constraint_schema, table_name, constraint_name FROM information_schema.referential_constraints WHERE unique_constraint_schema = 'shop' AND referenced_table_name = 'products';
OUTPUT
+-------------------+------------+------------------+
| CONSTRAINT_SCHEMA | TABLE_NAME | CONSTRAINT_NAME  |
+-------------------+------------+------------------+
| shop              | stock      | fk_stock_product |
| report            | sales      | fk_sales_product |
+-------------------+------------+------------------+
2 rows in set (0.00 sec)
Fixrun as root
ALTER TABLE report.sales DROP FOREIGN KEY fk_sales_product;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

Search information_schema.referential_constraints by unique_constraint_schema and referenced_table_name — it lists foreign keys from every database (shop.stock and report.sales here). After dropping the FK in report.sales, the same DROP succeeds.

After the fixrun as root
DROP TABLE shop.stock, shop.products;
SHOW TABLES FROM shop;
✓ SUCCESS
Query OK, 0 rows affected (0.02 sec)

Empty set (0.00 sec)

FAQ

How do I fix MySQL error 3730 Cannot drop table referenced by a foreign key constraint?

The message names the constraint and the child table. Drop that foreign key with ALTER TABLE child DROP FOREIGN KEY name, or drop the child table first, then drop the parent.

Can I drop both parent and child tables at once?

Yes. Put both in one statement, for example DROP TABLE IF EXISTS order_lines, orders.

How do I find which tables reference a table in MySQL?

Query information_schema.referential_constraints with referenced_table_name and unique_constraint_schema. It also shows foreign keys from other databases.

What is the difference between 3730 and 1451?

3730 is raised by DROP TABLE on a referenced table. 1451 is raised by DELETE or UPDATE of parent rows that child rows still use.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13