duplicate key value violates unique constrain
Hi, I'm new to supabase and I'm developping a Flutter App.
I have manage to create table and data and query, but I'm facing an error when trying to insert a new row.
Every time I run the method to insert a new row, a get the following error:
"duplicate key value violates unique constrain".
But the thing is: I'm not passing the id column at all and it is set as unique identity not nullable. I even tried to double check and run SQL prompt to update the id column to 'GENERATED ALWAYS' as described in the docs, and commands runs without any error, but still getting the same error message to insert. Could some please advise me what I'm missing? thanks in adv
6 Replies
Check your Postgres logs and it should give you more information.
There are only entries related to connection authenticaded and authorized, but no errors or other severity levels. There is something specific that I should look for?
Either go back in time or hit the filter up top for error.
Took a while to display, there is an error log now, but it's the same message from the Flutter Debug. The only detail that it contains is ""detail": "Key (id)=(###) already exists." the ### increments on every run. I imported some CSV data in the dashboard for testing. Would be that the reason? And if so, there is any good way to fix it? Because there will be several imports to be made when on in production.
That is your problem... importing CSV with numbers for the column
You have to leave that column out, or set the sequence higher than your highest id after you import.
Just one quick hit: https://stackoverflow.com/questions/66226363/postgresql-update-sequence-after-importing-data-from-csv
Or go with UUID's...
I see. With the command sequence you pointed, I was able to get it working now. Thanks a lot for you help!! 👍 I'll try using uuid next