Auto-increment field with Prisma
· 2 min read
This post is a knowledgebase article on Prisma with PostgreSQL.
The typical model in a Prisma schema has an id
field that auto-increments:
model User {
id Int @id @default(autoincrement())
name String
}
The following is working (most of the time) code that inserts a new entry:
prisma.user.create({
data: { name: 'Some User' },
});
However, the following error may occur:
Unique constraint failed on the fields: (id
)
This is baffling - if the field auto-increments, how can the unique constraint be violated?