3730: Cannot drop table referenced by a foreign key constraint
MySQLWhat does it mean?
The table cannot be dropped because another table's foreign key references it. As long as the reference exists, DROP is blocked.
Why does it happen?
Trying to drop a parent table while child tables linked to it by an FK still exist; not respecting the dependency order; not removing the foreign keys first.
How to fix it
First remove the referencing foreign key: ALTER TABLE child_table DROP FOREIGN KEY fk_name; then drop the table. Find dependent tables/constraints: SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME = 'my_table'; In bulk operations, SET FOREIGN_KEY_CHECKS = 0; can be used temporarily, but be careful and set it back to 1 afterwards.
More from this engine
- 1093You can't specify target table 'x' for update in FROM clause
- 1305PROCEDURE does not exist
- 1227Access denied; you need (at least one of) the PRIVILEGE
- 2013Lost connection to MySQL server during query
- 1153Got a packet bigger than 'max_allowed_packet' bytes
- 1969MariaDB: Query execution was interrupted (max_statement_time exceeded)
- 1927MariaDB: ER_CONNECTION_KILLED: Connection was killed