Unique constrain error, id still incremented
Hi folks,
so I have moved from TypeORM to DrizzleORM and I love it!
I encountered an issue recently where I have a unique constrain on my email field:
When I try to save the user, everything works, I get my user with id , for example
10
. Now when I try to save the same user, I get my nice error message: "detail": "Key (email)=(john.doe@example.com) already exists."
.
The issue comes when I try to save a new user now. Instead of saving a new user with id 11
, it skips the one it tried to save when unique constrain error was thrown and save the new user with id 12
. Any ideas how to fix this please ?3 Replies
This is how the database will work
There is a way to reset the count in any case
Cheers mate, if that's how it should behave then I can live with it. Was just wondering if I am not doing anything wrong. Thanks!
https://stackoverflow.com/questions/5342440/reset-auto-increment-counter-in-postgres/5342503#5342503
Stack Overflow
Reset auto increment counter in postgres
I would like to force the auto increment field of a table to some value, I tried with this:
ALTER TABLE product AUTO_INCREMENT = 1453
AND
ALTER SEQUENCE product RESTART WITH 1453;
ERROR: relation &