How to fix "createMany does not exists..." in prisma?
Asked Answered
E

2

12

I'm planning to create a seeder for my projects table. I'm using createMany to insert multiple data in just a query (see code below). But the problem is, it does not recognize createMany and throws and error after running a jest test.

Another thing that is confusing me, there was no typescript error in my code. And I can create also single data using create function.

I already been to prisma documentation, but I can't determine what was wrong in my code. Could someone help me figure it out. (comments would also help).

error TS2339: Property 'createMany' does not exist on type 'ProviderDelegate<RejectOnNotFound | RejectPerOperation | undefined>'.


schema.prisma

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

model Provider {
  id Int @id @default(autoincrement())
  user_id Int
  name String
  space_key String
  api_key String
  projects Project[]
  created_at DateTime @default(now())
  updated_at DateTime @updatedAt
  @@unique([user_id, api_key])
}

my usage

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

...

await prisma.provider.createMany({
  data: [
    {
      user_id: 1,
      name: 'Nicole Sal',
      space_key: 'nic_spa',
      api_key: 'nic_api',
      created_at: new Date(),
      updated_at: new Date()
    },
    // ... more data here (same at above)
  ]
})
Electrophorus answered 30/5, 2022 at 11:9 Comment(0)
E
28

Ahh I see. just found this. createMany is not supported for SQLite.

createMany is not supported on SQLite unfortunately: #10710 Documented here: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#remarks-10

https://github.com/prisma/prisma/issues/11507#issuecomment-1025587202

Electrophorus answered 30/5, 2022 at 11:22 Comment(0)
Z
0

Update: Prisma now supports createMany on SQLite, see https://www.prisma.io/docs/orm/reference/prisma-client-reference#createmany

However, note that:

You cannot create or connect relations by using nested create, createMany, connect, connectOrCreate queries inside a top-level createMany() query.

If this is why you aren't seeing the function, there's good news:

You can use a nested a createMany query inside an update() or create() query - for example, add a User and two Post records with a nested createMany at the same time.

Zennie answered 15/4 at 18:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.