understanding drizzle insert

I am trying to use insert in drizzle orm and it is requiring the id for the model:
export const meetings = mysqlTable("meetings", {
id: varchar("id", { length: 255 }).notNull().primaryKey(),
clubId: varchar("clubId", { length: 255 }).notNull(),
name: varchar("name", { length: 255 }).notNull(),
description: varchar("description", { length: 255 }).notNull(),
image: varchar("image", { length: 255 }).notNull(),
isPublic: boolean("isPublic").default(false).notNull(),
date: timestamp("date", { mode: "date" }).notNull(),
});
export const meetings = mysqlTable("meetings", {
id: varchar("id", { length: 255 }).notNull().primaryKey(),
clubId: varchar("clubId", { length: 255 }).notNull(),
name: varchar("name", { length: 255 }).notNull(),
description: varchar("description", { length: 255 }).notNull(),
image: varchar("image", { length: 255 }).notNull(),
isPublic: boolean("isPublic").default(false).notNull(),
date: timestamp("date", { mode: "date" }).notNull(),
});
code:
create: protectedProcedure
.input(
z.object({
date: z.date(),
clubId: z.string(),
name: z.string(),
description: z.string(),
isPublic: z.boolean(),
image: z.string(),
})
)
.mutation(async ({ input, ctx }) => {
return await ctx.db.insert(meetings).values(input);
}),
create: protectedProcedure
.input(
z.object({
date: z.date(),
clubId: z.string(),
name: z.string(),
description: z.string(),
isPublic: z.boolean(),
image: z.string(),
})
)
.mutation(async ({ input, ctx }) => {
return await ctx.db.insert(meetings).values(input);
}),
error disperses when I add id to the schema, I was under the assumption that id is not required because it is auto generated?
Solution:
needed to use .autoincrement() in mysql
Jump to solution
3 Replies
Solution
Ani
Ani2y ago
needed to use .autoincrement() in mysql
Ani
AniOP2y ago
thanks
Want results from more Discord servers?
Add your server