I'm using a prismia db client with postgresql and I'd like to start auto incrementing an integer field from 0 instead of 1. In other words, how can I write a model so that it starts from 0?
Here's the modal I have.
model SortableItem {
id String @id @default(uuid())
name String
order Int @default(autoincrement())
}
With this implementation, when a record is inserted for the first time, the order starts from 1, but I'd like it to start from 0.
I know postgresql has RESTART to achieve this, but I couldn't find anything equivalent for prisma ORM syntax.
ALTER SEQUENCE tablename_columnname_seq RESTART WITH 0;
It's not possible from the schema directly but you can add this to your migration SQL and it should work:
Create a migration using prisma migrate dev --create-only.
Edit the generated .sql file and add the above statement.
Run prisma migrate dev.
The following steps will alter the sequence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With