© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
2 replies
Vithrax

createInsertSchema

Hi,

I have small issue with createInsertSchema function. Optional columns can have value or be undefined or null - and null type conflicts with HTMLInputElement attributes. I can't find a way to override the type to be value | undefined.

Do you have any suggestions on how to tackle this? Code below

export const recipes = createTable("recipe", {
  id: int("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
  name: text("name", { length: 256 }).notNull(),
  description: text("description", { length: 256 }),
  image: text("image", { length: 256 }),
  cookingTime: int("cookingTime", { mode: "number" }),
  favorite: int("favorite", { mode: "boolean" }),
  createdBy: text("createdBy", { length: 255 })
    .notNull()
    .references(() => users.id),
  createdAt: int("created_at", { mode: "timestamp" })
    .default(sql`CURRENT_TIMESTAMP`)
    .notNull(),
  updatedAt: int("updatedAt", { mode: "timestamp" }),
});

export const NewRecipeSchema = createInsertSchema(recipes);
export type NewRecipe = z.infer<typeof NewRecipeSchema>;
export const recipes = createTable("recipe", {
  id: int("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
  name: text("name", { length: 256 }).notNull(),
  description: text("description", { length: 256 }),
  image: text("image", { length: 256 }),
  cookingTime: int("cookingTime", { mode: "number" }),
  favorite: int("favorite", { mode: "boolean" }),
  createdBy: text("createdBy", { length: 255 })
    .notNull()
    .references(() => users.id),
  createdAt: int("created_at", { mode: "timestamp" })
    .default(sql`CURRENT_TIMESTAMP`)
    .notNull(),
  updatedAt: int("updatedAt", { mode: "timestamp" }),
});

export const NewRecipeSchema = createInsertSchema(recipes);
export type NewRecipe = z.infer<typeof NewRecipeSchema>;


NewRecipe type is

type NewRecipe = {
    name: string;
    createdBy: string;
    id?: number | undefined;
    description?: string | null | undefined;
    image?: string | null | undefined;
    cookingTime?: number | null | undefined;
    favorite?: boolean | ... 1 more ... | undefined;
    createdAt?: Date | undefined;
    updatedAt?: Date | ... 1 more ... | undefined;
}
type NewRecipe = {
    name: string;
    createdBy: string;
    id?: number | undefined;
    description?: string | null | undefined;
    image?: string | null | undefined;
    cookingTime?: number | null | undefined;
    favorite?: boolean | ... 1 more ... | undefined;
    createdAt?: Date | undefined;
    updatedAt?: Date | ... 1 more ... | undefined;
}


Just for clarity, i want to change, for example, description to be string | undefined.
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

refine and createInsertSchema
Drizzle TeamDTDrizzle Team / help
13mo ago
[postgres][zod] createInsertSchema
Drizzle TeamDTDrizzle Team / help
2y ago
createInsertSchema & createSelectSchema difference
Drizzle TeamDTDrizzle Team / help
3y ago
createInsertSchema fails to infer
Drizzle TeamDTDrizzle Team / help
8mo ago