When using createInsertSchema from drizzle-zod, primaryKey is defined as number | undefined #2141
-
I have this table export const authors = sqliteTable('authors', {
id: integer('id').primaryKey({ autoIncrement: true }),
});
export const insertAuthorsSchema = createInsertSchema(authors); and produced type looks like this const insertAuthorsSchema: ZodObject<{
id: ZodOptional<ZodNumber>;
}, UnknownKeysParam, ZodTypeAny, {
id?: number | undefined;
}, {
id?: number | undefined;
}> But why it's optional, shouldn't it be mandatory since it's primary key? I tried to look into Just now I noticed export const authors = sqliteTable(
'authors',
{
id: integer('id').primaryKey({ autoIncrement: true }),
},
(t) => ({
pk: primaryKey({ columns: [t.id] }),
}),
); I still see no difference. Inserting |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's not required for insert schema because the database is handling the primary key generation. |
Beta Was this translation helpful? Give feedback.
It's not required for insert schema because the database is handling the primary key generation.