Alban Kaperi
05/11/2022, 11:13 AMconst customerData: Prisma.CustomerCreateInput[] = [
{
name: 'Alice',
surname: 'Kaperi',
email: '<mailto:alice@prisma.io|alice@prisma.io>',
products: {
create: [
{
title: 'Apples',
description: 'These are juicy apples',
price: 12.5,
},
],
},
},
]
my schema has the following:
model Customer {
id Int @id @default(autoincrement())
email String @unique
name String?
surname String?
phone String?
code String @unique
total_sale Float
total_quantity Int
points Int
address String
products Product[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Product {
id Int @id @default(autoincrement())
title String
description String?
size String?
qty Int? @default(0)
cost Float
price Float
upc Int
reorder_point Int
manufactuerer String
last_received DateTime @default(now())
picture String
customer Customer? @relation(fields: [customerId], references: [id])
customerId Int?
department Department? @relation(fields: [departmentId], references: [id])
departmentId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}Irek Prucnal
05/11/2022, 11:24 AMproducts: {
create: [
{
title: 'Apples',
description: 'These are juicy apples',
price: 12.5,
},
],
},
create doesn't accept an array and you've put square brackets here. I think it should work if you just remove the square brackets. If you need to create more products though, have a look at createManyAlban Kaperi
05/11/2022, 11:29 AMAlban Kaperi
05/11/2022, 11:30 AMIrek Prucnal
05/11/2022, 11:57 AMIrek Prucnal
05/11/2022, 12:00 PMIrek Prucnal
05/11/2022, 12:07 PMNurul
05/11/2022, 12:18 PMawait prisma.customer.create({
data: {
name: 'Alice',
surname: 'Kaperi',
email: '<mailto:alice@prisma.io|alice@prisma.io>',
address: '123 Main St',
code: '12345',
points: 0,
total_quantity: 0,
total_sale: 0,
products: {
createMany: {
data: [
{
cost: 0,
manufactuerer: 'abc',
picture: 'abc',
price: 0,
reorder_point: 0,
title: 'abc',
upc: 0,
},
],
},
},
},
});Alban Kaperi
05/11/2022, 2:22 PMSError: ⨯ Unable to compile TypeScript:
prisma/seed.ts:19:17 - error TS2322: Type '{ createMany: { data: { cost: number; manufactuerer: string; picture: string; price: number; reorder_point: number; title: string; upc: number; }[]; }; }' is not assignable to type 'ProductUncheckedCreateNestedManyWithoutCustomerInput | ProductCreateNestedManyWithoutCustomerInput | undefined'.
Object literal may only specify known properties, and 'createMany' does not exist in type 'ProductUncheckedCreateNestedManyWithoutCustomerInput | ProductCreateNestedManyWithoutCustomerInput'.Alban Kaperi
05/11/2022, 2:24 PMNurul
05/11/2022, 3:08 PMAlban Kaperi
05/12/2022, 8:03 PM