Vladimír Gál
Vladimír Gál
Explore posts from servers
DTDrizzle Team
Created by Vladimír Gál on 1/11/2024 in #help
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:
export const users = pgTable("users", {
...
email: varchar("email", { length: 256 }).unique().notNull(),
});
export const users = pgTable("users", {
...
email: varchar("email", { length: 256 }).unique().notNull(),
});
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 ?
5 replies