Id being required in types when using insert and values
Hello! I' been following the tutorial and I'm having a issue with the following function:
I'm getting the following error:
and this is my schema:
What could be happening?
6 Replies
Primary Key is
not null
by default, and you've not specified a default value.What should i do? Is primary key auto-increment? I searched through the docs and couldn't find anything related to.
As an integer, no. Use serial type.
https://orm.drizzle.team/docs/column-types/pg
https://orm.drizzle.team/docs/column-types/pg#serial
Drizzle ORM - PostgreSQL column types
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Thank you so much for taking time helping me. Unfortunately, this couldn't solve the typescript type issue I'm having. My issue is with primary key. I'm just following the tutorial on the drizzle page, and when i call insert(todo).values, typescript throws and erros telling me that id missing from the values.
You are required to provide it, because integer primary keys do not have a default value out of the box.
Oh, you're right. My fault. I was missing it. I tried and it worked now. Thank you again for your time.