迁移数据库时,出现以下错误:
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,我很乐意将其删除。
谢谢
最佳答案
我通过从 DB shell 手动删除记录解决了这个问题。 (因为前端没有出现记录)
manage.py dbshell
delete from table
WHERE NOT EXISTS (SELECT 1 FROM other_table t WHERE table.id = other_table.foreign_key)
关于Django Migrate - 行具有无效的外键,但行不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56600685/