peewee: Duplicate PKEY even when setting the id_seq
Hi @coleifer.
We’ve been having a problem similar to this since we’ve migrated from dynamoDB to PostgreSQL using Peewee.
Our migration scripts used peewee to create the items in the DB. Now, randomly, when we want to create a new item from one or another service, it randomly fails.
We’ll get a duplicate key value violates unique constraint "evaluationattempts_pkey" DETAIL: Key (id)=(118454) already exists. sometimes, but not always. a new evaluationattempts can be created from multiple different places, could it be a session problem ? The main service is a Flask API and follows your recommendation here
I’ve been looking around online for the past week and couldn’t find anything. I have done multiple times this
SELECT setval('users_id_seq', (SELECT MAX(id) FROM users)+1);
for the tables that are affected but it keeps happening. In the last 7 days, we’ve had this duplicate pkey error about 200 times, but we cannot figure out why.
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 1
- Comments: 16 (9 by maintainers)
Glad we got to the bottom of it, you’re very welcome.