迁移时表“auth_user”中不存在错误键 (user_id)=(1)

Jib*_*ews 5 django postgresql

我在迁移时遇到了这个错误。有什么办法可以在我的数据库中保存数据。我知道删除 auth_user 表可以解决这个问题。我正在运行 postgresql。谢谢!

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".
Run Code Online (Sandbox Code Playgroud)

Lau*_*lbe 3

有一行api_poiuser_id设置为 1,但没有行auth_userid设置为 1。

因此不可能像您尝试那样定义外键约束。

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