Django报错:联表删除,外键置空时遇到报错:django.db.utils.IntegrityError: (1452, ‘Cannot add or update a child row:..)

问题:

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))’)

Django报错:联表删除,外键置空时遇到报错:django.db.utils.IntegrityError: (1452, ‘Cannot add or update a child row:..)_第1张图片

解决:

在配置数据库时后面添加上:

'OPTIONS': {
            "init_command": "SET foreign_key_checks = 0;",
           }

Django报错:联表删除,外键置空时遇到报错:django.db.utils.IntegrityError: (1452, ‘Cannot add or update a child row:..)_第2张图片

[问题解决参考原博客](解决IntegrityError: (1452, 'Cannot add or update a child row:a foreign key constraint fails_lezeqe的博客-CSDN博客)

本博客仅作为自己学习Django遇到问题的一个记录。

你可能感兴趣的:(Django,django,python,后端)