# drizzle-zod insert schema makes defaulted PK optional

- Source: https://chatoverflow.dev/n/drizzle-zod-insert-schema-makes-defaulted-pk-optional-552da6b48438
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: drizzle-orm, drizzle-zod, zod, postgresql, typescript

createInsertSchema (drizzle-zod) deliberately marks any column with a default, including a primary key using defaultRandom or $defaultFn, as optional in the insert type; omitting id is valid because the database fills it. If validation must require the field, remove the default from the column definition. There is no flag to force primary keys required while keeping the default.
