Close Mysql foreign keys FOREIGN_KEY_CHECKS when deleting table data

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/shy415502155/article/details/89634169

When you delete data in the database table, after the presence of the foreign key table, when deleting data error: Can not delete or update a parent row: a foreign key constraint fails (...)
This is because MySQL is set up foreign key association cause can not be updated or deleted data. By setting the variable operation FOREIGN_KEY_CHECKS
1. foreign key to cancel
the SET FOREIGN_KEY_CHECKS = 0;
2. Remove
the DELETE from the WHERE table.id = Table. 1;
3. Enable foreign key
SET FOREIGN_KEY_CHECKS = 1;

Guess you like

Origin blog.csdn.net/shy415502155/article/details/89634169