본문 바로가기
ERROR

IntegrityError: 1452 (23000): Cannot add or update a child row: a foreign key constraint fails

by ram_ 2022. 12. 11.

The Problem is with FOREIGN KEY Constraint. By Default (SET FOREIGN_KEY_CHECKS = 1). FOREIGN_KEY_CHECKS option specifies whether or not to check foreign key constraints for InnoDB tables.

 MySQL - SET FOREIGN_KEY_CHECKS

We can set foreign key check as disable before running Query. Disable Foreign key.

Execute one of these lines before running your query, then you can run your query successfully. :)

 

***** SET FOREIGN_KEY_CHECKS = 0 추가해서 코드 다시 돌렸다.

주의할 것은, 이후에 다시 디폴트 값이었던 =1 으로 set 되돌려주어야 한다.

 

 

 

  • 참고 링크

https://stackoverflow.com/questions/21659691/error-1452-cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails

 

ERROR 1452: Cannot add or update a child row: a foreign key constraint fails

I have created tables in MySQL Workbench as shown below : ORDRE table: CREATE TABLE Ordre ( OrdreID INT NOT NULL, OrdreDato DATE DEFAULT NULL, KundeID INT DEFAULT NULL, CONSTRAINT Or...

stackoverflow.com