Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Key (user_id)=(1) is not present in table "auth_user" when migrating

I am running into this error when i migrate.Is there any way to save data on my database.I know that dropping the auth_user table will fix the issue. I am running postgresql. Thanks!

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".
like image 758
Jibin Mathews Avatar asked Oct 19 '22 01:10

Jibin Mathews


1 Answers

There is a row in api_poi which has user_id set to 1, but there is no row in auth_user which has id set to 1.

So it is impossible to define a foreign key constraint like you are trying to do.

You will have to add rows to auth_user or remove rows from api_poi until the foreign key constraint is satisfied.

like image 157
Laurenz Albe Avatar answered Oct 30 '22 22:10

Laurenz Albe