迁移数据库时,出现以下错误:
The row in table 'project_obicase' with primary key '2325' has an invalid foreign key: project_obicase.ckId_id contains a value '2443' that does not have a corresponding value in project_pupiladdressck.id.
在我的/ admin /网站中,我找不到此记录'2325'。它从2324跳到2333
project_obicase表:
如果找不到对象,是否有任何方法可以解决此外键事故?如果能找到记录,我很乐意删除记录2325。
谢谢
答案 0 :(得分:0)
我通过从DB Shell手动删除记录来解决了这个问题。 (因为记录未出现在前端)
manage.py dbshell
delete from table
WHERE NOT EXISTS (SELECT 1 FROM other_table t WHERE table.id = other_table.foreign_key)