© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
1 reply
DiamondDragon

createInsertSchema does not infer notNull() correclty?

"drizzle-orm": "^0.28.6",
"drizzle-zod": "^0.5.1",

export const testTable = pgTable('accounts', {
    id: varchar('id').primaryKey(),
    optional: varchar('optional'),
    notOptional: varchar('not_optional').notNull(),
    unique: varchar('unique').unique().notNull(),
})

const testSchema = createInsertSchema(testTable)
type TestTypeWrong = z.infer<typeof testSchema>
type TestTypeCorrect = typeof testTable.$inferInsert
export const testTable = pgTable('accounts', {
    id: varchar('id').primaryKey(),
    optional: varchar('optional'),
    notOptional: varchar('not_optional').notNull(),
    unique: varchar('unique').unique().notNull(),
})

const testSchema = createInsertSchema(testTable)
type TestTypeWrong = z.infer<typeof testSchema>
type TestTypeCorrect = typeof testTable.$inferInsert

Results

type TestTypeWrong = {
    id?: string;
    optional?: string;
    notOptional?: string;
    unique?: string;
}
type TestTypeCorrect = {
    id: string;
    notOptional: string;
    unique: string;
    optional?: string;
}
type TestTypeWrong = {
    id?: string;
    optional?: string;
    notOptional?: string;
    unique?: string;
}
type TestTypeCorrect = {
    id: string;
    notOptional: string;
    unique: string;
    optional?: string;
}
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

createSelectSchema & createInsertSchema does not infer array properly
Drizzle TeamDTDrizzle Team / help
3y ago
createInsertSchema fails to infer
Drizzle TeamDTDrizzle Team / help
8mo ago
createInsertSchema
Drizzle TeamDTDrizzle Team / help
2y ago
Property notNull does not exist on type 'PgEnum<[google, github]>
Drizzle TeamDTDrizzle Team / help
2y ago