Phenomenon
MySQL appears when deleting a table
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
Why
It may be that in mysql, the foreign key association is set between the deleted table and another table, which makes it impossible to update or delete data
Solutions
By setting foreign_ KEY_ Checks variable to avoid this
Disable foreign key constraints
SET FOREIGN_KEY_CHECKS = 0;
Then you can delete the table
Start the foreign key constraint after deletion
SET FOREIGN_KEY_CHECKS = 1;
View current foreign_ KEY_ The value of checks can be determined by the following command
SELECT @@FOREIGN_KEY_CHECKS;
Attention
This setting will only affect the current session, not the global
If you want to set global variables, you can write like this
SET GLOBAL FOREIGN_KEY_CHECKS = 0;
Similar Posts:
- [Solved] MYSQL Error: Cannot delete or update a parent row: a foreign key constraint fails
- ORA-02292: integrity constraint
- MySQL ERROR 1005: Can’t create table (errno: 150) [How to Solve]
- Prepared statement needs to be re prepared
- [Solved] MySQL Error: ERROR 1615 (HY000): Prepared statement needs to be re-prepared
- The ‘INFORMATION_SCHEMA.GLOBAL_STATUS’ feature is disabled; see the documentation for …
- You can’t specify target table for update….
- MySQL exclude error 1114 holmium HY000 41 holmium“
- [Solved] MYSQL Error: You can’t specify target table for update in FROM clause
- activiti MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row