MySQL 8.4실제 DB 검증 · 2026-11-29

MySQL ERROR 3730 (HY000): 외래키가 참조하는 테이블 삭제 불가

다른 테이블의 외래키가 지우려는 테이블을 아직 참조하고 있어요.

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

원인 바로가기

  1. 01자식 테이블이 참조 중인 부모 테이블 DROP
  2. 02정리·재생성 스크립트가 부모를 자식보다 먼저 DROP
  3. 03다른 데이터베이스의 테이블이 참조 중

실제 DB 검증MySQL 8.4.13에서 재현·해결 확인 · 2026-11-29 · 컨테이너 이미지 mysql:8.4

메시지에 지우려던 테이블, 제약 이름, 그 제약을 가진 자식 테이블이 모두 나와요. 예: Cannot drop table 'customers' referenced by a foreign key constraint 'fk_orders_customer' on table 'orders'.

MySQL 8.0부터는 부모 테이블 DROP에 3730이 나요(예전 버전은 1217·1451). MySQL 8.4는 lc_messages를 한국어로 바꿔도 이 메시지는 영어로 내요.

01자식 테이블이 참조 중인 부모 테이블 DROP

orders.customer_id에 customers를 가리키는 외래키가 있어서, 행이 하나도 없어도 DROP TABLE customers가 거부돼요. 데이터가 아니라 제약 자체를 검사해요.

사전 준비
사전 준비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)
재현lab_a 계정으로 실행
DROP TABLE customers;
✕ 에러
ERROR 3730 (HY000): Cannot drop table 'customers' referenced by a foreign key constraint 'fk_orders_customer' on table 'orders'.
확인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)
해결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

information_schema.referential_constraints에서 참조하는 제약을 찾고 ALTER TABLE orders DROP FOREIGN KEY fk_orders_customer로 외래키를 지운 뒤 부모를 지우세요. orders는 남고 customers만 지워져요.

해결 후 재실행lab_a 계정으로 실행
DROP TABLE customers;
SHOW TABLES;
✓ 성공
Query OK, 0 rows affected (0.01 sec)

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

02정리·재생성 스크립트가 부모를 자식보다 먼저 DROP

order_lines가 남아서 참조하고 있으니 DROP TABLE IF EXISTS orders가 실패해요. IF EXISTS는 없는 테이블만 건너뛰지, 외래키 검사는 건너뛰지 않아요.

사전 준비
사전 준비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)
재현lab_a 계정으로 실행
DROP TABLE IF EXISTS orders;
✕ 에러
ERROR 3730 (HY000): Cannot drop table 'orders' referenced by a foreign key constraint 'fk_lines_order' on table 'order_lines'.
확인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 TABLE IF EXISTS order_lines, orders. 둘 다 지워지고 SHOW TABLES가 비어요.

해결 후 재실행lab_a 계정으로 실행
DROP TABLE IF EXISTS order_lines, orders;
SHOW TABLES;
✓ 성공
Query OK, 0 rows affected (0.02 sec)

Empty set (0.00 sec)

03다른 데이터베이스의 테이블이 참조 중

shop.stock과 shop.products를 같이 지워도 실패해요. 메시지의 fk_sales_product(테이블 sales)는 report 데이터베이스에 있어요. 메시지에 DB 이름이 안 나와서 놓치기 쉬워요.

사전 준비
사전 준비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)
재현root 계정으로 실행
DROP TABLE shop.stock, shop.products;
✕ 에러
ERROR 3730 (HY000): Cannot drop table 'products' referenced by a foreign key constraint 'fk_sales_product' on table 'sales'.
확인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)
해결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

information_schema.referential_constraints를 unique_constraint_schema와 referenced_table_name으로 조회하면 모든 DB의 외래키가 나와요(여기서는 shop.stock, report.sales). report.sales의 외래키를 지우면 같은 DROP이 성공해요.

해결 후 재실행root 계정으로 실행
DROP TABLE shop.stock, shop.products;
SHOW TABLES FROM shop;
✓ 성공
Query OK, 0 rows affected (0.02 sec)

Empty set (0.00 sec)

자주 묻는 질문

MySQL 3730 Cannot drop table referenced by a foreign key constraint 해결 방법은?

메시지에 나온 제약과 자식 테이블을 보고 ALTER TABLE 자식 DROP FOREIGN KEY 제약명으로 외래키를 지우거나, 자식 테이블을 먼저 지운 뒤 부모를 지우세요.

부모·자식 테이블을 한 번에 지울 수 있나요?

네. DROP TABLE IF EXISTS order_lines, orders처럼 한 문장에 둘 다 쓰면 돼요.

MySQL에서 어떤 테이블이 참조하는지 찾는 법

information_schema.referential_constraints를 referenced_table_name과 unique_constraint_schema로 조회하세요. 다른 DB의 외래키도 나와요.

3730과 1451 차이는?

3730은 참조되는 테이블을 DROP할 때, 1451은 자식이 쓰는 부모 행을 DELETE·UPDATE할 때 나요.

검증 방법

시나리오마다 새 DB 사용자를 만들어 시작해요. 스크립트가 사전 준비 → 에러 재현(에러 코드 일치 확인) → 해결 → 원래 문장 재실행 순서로 실행하고, 화면의 출력은 DB가 실제로 낸 결과를 스크립트가 그대로 저장한 거예요.

lab_a, lab_b는 테스트용 일반 사용자(같은 이름의 데이터베이스가 기본, 그 안에서 모든 권한), root는 관리자예요. MySQL 8.4.13