2016-09-21 32 views
0

当我迁移时遇到此错误。是否有任何方法将数据保存在我的数据库中。我知道,删除auth_user表将解决这个问题。我正在运行postgresql。 谢谢!当迁移时,错误键(user_id)=(1)在表“auth_user”中不存在

FATAL ERROR - The following SQL query failed: ALTER TABLE "api_poi" ADD CONSTRAINT "user_id_refs_id_20f256ff" FOREIGN KEY ("user_id") REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED; 
The error was: insert or update on table "api_poi" violates foreign key constraint "user_id_refs_id_20f256ff" 
DETAIL: Key (user_id)=(1) is not present in table "auth_user". 
+0

@Sagar我认为你知道该表不包含所需的数据,因为你建议删除所有内容?这将有助于提及这一点。 –

+0

因为您仍然拥有引用表的表“api_poi”,所以删除'auth_user'不会有帮助。您可以删除引用未在数据库中找到的用户的行,然后约束将成功。 –

+0

但poi表没有引用用户的行 –

回答

1

有在api_poi一排具有user_id设置为1,但在auth_user没有行具有id设置为1

所以这是不可能的定义像你这样的外键约束正在努力去做。

您必须将行添加到auth_user或从api_poi删除行,直到满足外键约束为止。

相关问题