S
Supabase2y ago
loup

duplicate key value violates unique constraint Key (id)=(5)

Okay Im becoming crazy ahah, in multiple table, when I delete some row and after reupload data, im getting this error :
duplicate key value violates unique constraint "tmdb_collection_translations_pkey"
DETAIL: Key (id)=(5) already exists.
duplicate key value violates unique constraint "tmdb_collection_translations_pkey"
DETAIL: Key (id)=(5) already exists.
That doesnt make sense because the id should automatically set... Im using Supabase self hosted btw
5 Replies
loup
loupOP2y ago
And if I run again and again my script the id value grow : Key (id)=(7) already exists. Key (id)=(8) already exists. So I guess the problem is because Ive upload my data in csv. and maybe the unique id are broken
vick
vick2y ago
You need to set the corresponding sequence for your PK to start at the highest value you've already got in there. It doesn't look for the next available value, it just increments a sequence and uses the next value.
loup
loupOP2y ago
When I do : SELECT PG_GET_SERIAL_SEQUENCE('tmdb_collection_translation', 'id'); Im getting this
loup
loupOP2y ago
No description
loup
loupOP2y ago
But if is take the serial sequence another table its working Okay its fixed Ive duplicate the table

Did you find this page helpful?