참조무결성1 [Django, mysql 에러] mysql.connector.errors.integrityerror: 1452 (23000): cannot add or update a child row: a foreign key constraint fails Django에서 mysql을 연동한 상태에서 makemigrations을 진행하고 migrate를 진행할 때 이러한 오류가 발생했다. mysql.connector.errors.integrityerror: 1452 (23000): cannot add or update a child row: a foreign key constraint fails 검색해 보니 참조 무결성에 어긋났기 때문에 migrate를 진행할 수 없다고 했다. 일단 원인은 다음과 같다. 1. A라는 model이 B를 fk로 참조한다. 2. B라는 model이 C를 fk로 참조한다. 3. 이때 A라는 모델이 추가로 C를 fk로 참조하는 경우, 문제가 발생하게 된다. 이 모델을 참조하는 것 자체는 문제가 발생하지 않으나 a(A의 object).. 2021. 10. 21. 이전 1 다음