I have this error for title, description, and pric...
# orm-help
a
I have this error for title, description, and price: (property) title: string Type 'string' is not assignable to type 'never'
Copy code
const 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:
Copy code
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
}
i
I think the problem might be with this part:
Copy code
products: {
            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
createMany
a
and there it accepts an array
i
oh, interesting, the docs didn't say that at all
or so I thought, it actually does 🙂 thanks for pointing that out
another thing that comes to my mind is that you don't provide all required data, your Product model has no default for manufacturer or cost, and they're missing in your create payload.
n
Can you try this query? I just checked and it worked for me
Copy code
await 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,
            },
          ],
        },
      },
    },
  });
a
@Nurul
Copy code
SError: ⨯ 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'.
I have not mentioned in the first comment that I am using sqlite, I will try to switch to PostgreSQL or MySQL not sure if that has any impact
n
Oh! SQLite doesn’t support createMany 😅 That’s the reason for this error
a
@Irek Prucnal @Nurul thank you both for the help, it seems it went away when I made most of the fields nullable with ?
👍 2