Russell
Russell
DTDrizzle Team
Created by Russell on 2/4/2024 in #help
Issue when inserting
export const plan = pgTable("plans",{
id: uuid("id").primaryKey().notNull(),
userId: text("user_id").notNull().references(() => user.id),
budget: integer("budget").notNull(),
city: text("city").notNull(),
startDate:date("start_date").notNull(),
endDate:date("end_date").notNull(),
groupSize: integer("group_size").notNull(),
rating: integer("rating")
})

const planData = await db.insert(plan)
.values({
userId: "d",
budget: 222,
city: "WOW",
startDate: new Date(),
endDate: new Date(),
groupSize: 1
})
.returning()
export const plan = pgTable("plans",{
id: uuid("id").primaryKey().notNull(),
userId: text("user_id").notNull().references(() => user.id),
budget: integer("budget").notNull(),
city: text("city").notNull(),
startDate:date("start_date").notNull(),
endDate:date("end_date").notNull(),
groupSize: integer("group_size").notNull(),
rating: integer("rating")
})

const planData = await db.insert(plan)
.values({
userId: "d",
budget: 222,
city: "WOW",
startDate: new Date(),
endDate: new Date(),
groupSize: 1
})
.returning()
I get the error on userId
No overload matches this call.
Overload 2 of 2, '(values: { userId: string | SQL<unknown> | Placeholder<string, any>; id: string | SQL<unknown> | Placeholder<string, any>; budget: number | SQL<unknown> | Placeholder<string, any>; ... 4 more ...; rating?: number | ... 3 more ... | undefined; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'userId' does not exist in type '{ userId: string | SQL<unknown> | Placeholder<string, any>; id: string | SQL<unknown> | Placeholder<string, any>; budget: number | SQL<unknown> | Placeholder<string, any>; ... 4 more ...; rating?: number | ... 3 more ... | undefined; }[]'.ts(2769)
No overload matches this call.
Overload 2 of 2, '(values: { userId: string | SQL<unknown> | Placeholder<string, any>; id: string | SQL<unknown> | Placeholder<string, any>; budget: number | SQL<unknown> | Placeholder<string, any>; ... 4 more ...; rating?: number | ... 3 more ... | undefined; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'userId' does not exist in type '{ userId: string | SQL<unknown> | Placeholder<string, any>; id: string | SQL<unknown> | Placeholder<string, any>; budget: number | SQL<unknown> | Placeholder<string, any>; ... 4 more ...; rating?: number | ... 3 more ... | undefined; }[]'.ts(2769)
9 replies
DTDrizzle Team
Created by Russell on 9/1/2023 in #help
Handling self referencing foreign keys
I have the following code but am getting an error that says 'people' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022) How should I handle a self referencing foreign key like in my example below?
export const people = pgTable("people",{
id: uuid("id").primaryKey(),
name: text("name").notNull(),
parentId: uuid("parent_id").notNull().references(() => people.id)
})
export const people = pgTable("people",{
id: uuid("id").primaryKey(),
name: text("name").notNull(),
parentId: uuid("parent_id").notNull().references(() => people.id)
})
3 replies