Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Teamβ€’3y agoβ€’
4 replies
Liltripple_reid

drizzle asks for <table> `id` when doing insert

I guess the ID should be autogenerated by the database itself, but not sure why it's asking me to pass it as a value when doing
  // This throwns TS error saying that ID is missing
  const data = await db.insert(workspaces).values([
    {
      ownerId: session.user.id,
      company: parsed.data.company,
      name: parsed.data.name,
    },
  ]);
  // This throwns TS error saying that ID is missing
  const data = await db.insert(workspaces).values([
    {
      ownerId: session.user.id,
      company: parsed.data.company,
      name: parsed.data.name,
    },
  ]);


using mysql, @planetscale/database
my schemas:
export const workspaces = mysqlTable("workspaces", {
  id: varchar("id", { length: 255 }).primaryKey(),
  name: varchar("name", { length: 255 }).notNull(),
  company: varchar("company", { length: 255 }).notNull(),
  ownerId: varchar("ownerId", { length: 255 }).notNull(),
  createdAt: timestamp("createdAt", { mode: "date" }).notNull().defaultNow(),
});

export const workspacesPickedSchema = createInsertSchema(workspaces)
  .pick({
    name: true,
    company: true,
  })
  .required();
export const workspaces = mysqlTable("workspaces", {
  id: varchar("id", { length: 255 }).primaryKey(),
  name: varchar("name", { length: 255 }).notNull(),
  company: varchar("company", { length: 255 }).notNull(),
  ownerId: varchar("ownerId", { length: 255 }).notNull(),
  createdAt: timestamp("createdAt", { mode: "date" }).notNull().defaultNow(),
});

export const workspacesPickedSchema = createInsertSchema(workspaces)
  .pick({
    name: true,
    company: true,
  })
  .required();
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

drizzle-zod insert user without id
Drizzle TeamDTDrizzle Team / help
3y ago
drizzle-zod: remove ID from insert schema type
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle complains when I'm trying to insert into a table.
Drizzle TeamDTDrizzle Team / help
2y ago
Does Drizzle support MySQL's LAST_INSERT_ID function?
Drizzle TeamDTDrizzle Team / help
3y ago