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:
export const addTodo = async (text: string) => {
await db.insert(todo).values({
text: text,
done: false,
});
revalidatePath("/");
};
export const addTodo = async (text: string) => {
await db.insert(todo).values({
text: text,
done: false,
});
revalidatePath("/");
};
I'm getting the following error:
No overload matches this call.
Overload 1 of 2, '(value: { id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }): PgInsertBase<...>', gave the following error.
Argument of type '{ text: string; done: false; }' is not assignable to parameter of type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }'.
Property 'id' is missing in type '{ text: string; done: false; }' but required in type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }'.
Overload 2 of 2, '(values: { id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'text' does not exist in type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }[]'.ts(2769)
No overload matches this call.
Overload 1 of 2, '(value: { id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }): PgInsertBase<...>', gave the following error.
Argument of type '{ text: string; done: false; }' is not assignable to parameter of type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }'.
Property 'id' is missing in type '{ text: string; done: false; }' but required in type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }'.
Overload 2 of 2, '(values: { id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'text' does not exist in type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }[]'.ts(2769)
and this is my schema:
import { integer, text, boolean, pgTable } from "drizzle-orm/pg-core";

export const todo = pgTable("todo_test", {
id: integer("id").primaryKey(),
text: text("text").notNull(),
done: boolean("done").default(false).notNull(),
});
import { integer, text, boolean, pgTable } from "drizzle-orm/pg-core";

export const todo = pgTable("todo_test", {
id: integer("id").primaryKey(),
text: text("text").notNull(),
done: boolean("done").default(false).notNull(),
});
What could be happening?
S
Sillvva13d ago
Primary Key is not null by default, and you've not specified a default value.
C
chimelli13d ago
What should i do? Is primary key auto-increment? I searched through the docs and couldn't find anything related to.
S
Sillvva13d ago
Drizzle ORM - PostgreSQL column types
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
C
chimelli13d ago
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.
S
Sillvva13d ago
You are required to provide it, because integer primary keys do not have a default value out of the box.
C
chimelli13d ago
Oh, you're right. My fault. I was missing it. I tried and it worked now. Thank you again for your time.
Want results from more Discord servers?
Add your server
More Posts
Failed push to planetscaleEvery time I try to push my schema to Planetscale, I get the following error: ``` if (unsquashSelect parent rows where child existsI want to use a relational query to select all users and their posts where users have at least one pCreating a View with Turso/Sqlite```export const jobsView = sqliteView("jobsView").as((qb) => qb .select({ id: job.id, How to update "updated_at" column automaticly when related row is updated?Hello. I'm using PostgreSQL as a dbms. So driver is pg. I want to update the "updated_at" column wwrap migrations in transactiondoes drizzle wrap migrations in transaction?Error with Nested TransactionsI'm experiencing an issue with nested transactions on neon serverless 0.9.1, drizzle-orm 0.30.9, andSupabase branching w/ Drizzle?Does anyone know if it is possible to get Supabase branching working with Drizzle migrations? (httpsType inference is not working when findFirst is extractedHey typescript wizards, could anyone spot what I'm doing wrong here? ```ts type OrgTableQueryParamsDrizzle Query, Relationship Sub-QueryI have Domains and Products, and a pivot between them (DomainProducts). I'd like to query (`findFirMariaDB driver and generate migrationsThe company im working for insists on using MariaDB but im having issues generating migrations for mNaming Migrationshow do i set a name for a new migration when running `drizzle-kit generate:mysql` ? i tried setting [postgres][zod] createInsertSchemaHey! Trying to make my Sveltekit form schema. Here is my example: ```export const userAccessesFormSUse schema definition as normal typesI want to use my schema definition as a normal type. Basically what .select().from() returns - plainWhat is a recommended way to execute migration on CI ?Build facilities for migration assume it happens during app execution I don't sure it a good idea an