3730: Cannot drop table referenced by a foreign key constraint
MySQLO que significa?
A tabela não pode ser removida porque a foreign key de outra tabela a referencia. Enquanto a referência existir, o DROP fica bloqueado.
Por que acontece?
Tentativa de remover uma tabela pai enquanto ainda existem tabelas filhas ligadas a ela por uma FK; desrespeito à ordem de dependência; não remover as foreign keys antes.
Como resolver
Primeiro remova a foreign key que faz a referência: ALTER TABLE child_table DROP FOREIGN KEY fk_name; e então remova a tabela. Encontre as tabelas/constraints dependentes: SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME = 'my_table'; Em operações em massa, SET FOREIGN_KEY_CHECKS = 0; pode ser usado temporariamente, mas tenha cuidado e volte para 1 em seguida.
Mais entradas deste banco
- 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 (a conexão foi encerrada)