2016-09-21 29 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刪除行,直到滿足外鍵約束爲止。

相關問題