mysql deletes foreign chain index data, Cannot delete or update a parent row: a foreign key constraint fails problem solution

mysql deletes external link index data

Cannot delete or update a parent row: a foreign key constraint fails The solution to the problem
Query: DELETE FROM goodsWHERE goods_id= '11'
Error code: 1451
Cannot delete or update a parent row: a foreign key constraint fails ( webDB. goods_properties_detail, CONSTRAINT FK_rip_43FOREIGN KEY ( goods_id) REFERENCES goods( goods_id)) The
above is because a certain field of the record is used as an external link to another table in InnoDB. The external link will be automatically checked during the delete operation.
Solution 1: First determine to delete the associated data, and then delete (this is more in line with business logic and safer).

Solution 2: Do not check external links, set the FOREIGN_KEY_CHECKS variable:

SET FOREIGN_KEY_CHECKS = 0;
DELETE FROM `goods` WHERE `goods_id` = '11'

Set after deleting

SET FOREIGN_KEY_CHECKS = 1;

ps: Turn off uniqueness check

set unique_checks=0;
set unique_checks=1;

Guess you like

Origin blog.csdn.net/weixin_45627031/article/details/114759038