问题:
Django报错:django.db.utils.IntegrityError: (1452, ‘Cannot add or update a child row: a foreign key constraint fails (django
.company_employee
, CONSTRAINT company_employee_depart_id_9fa0588f_fk_company_department_id
FOREIGN KEY (depart_id
) REFERENCES company_department
(id
))’)
解决:
在配置数据库时后面添加上:
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
}
[问题解决参考原博客](解决IntegrityError: (1452, 'Cannot add or update a child row:a foreign key constraint fails_lezeqe的博客-CSDN博客)
本博客仅作为自己学习Django遇到问题的一个记录。