如何修复“创建者不存在……”在Prisma中?
我计划为我的项目
表创建一个播种机。我正在使用 createMany
将多个数据插入一个查询(请参见下面的代码)。但是问题是,它无法识别 createMany
并在进行开玩笑测试后抛出和错误。
另一件事使我感到困惑,我的代码中没有打字稿错误。我还可以使用创建
函数创建单个数据。
我已经去过Prisma文档,但是我无法确定我的代码中出了什么问题。有人可以帮我弄清楚吗? (评论也将有所帮助)。
错误ts2339:属性'CreateMany'不存在于类型'ProviderDelegate< defferonnotfound |拒绝性ploperation |未定义的>'。
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])
}
我的用法
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)
]
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
啊,我明白了。刚刚找到了这个。
createMany
不支持SQLITE。https://github.com/prisma/prisma/issues/11507#issuecomment-1025587202
Ahh I see. just found this.
createMany
is not supported for SQLite.https://github.com/prisma/prisma/issues/11507#issuecomment-1025587202
更新:Prisma现在支持Sqlite上的创建人,请参见
但是,请注意:
如果这是为什么您看不到功能的原因,有个好消息:
Update: Prisma now supports createMany on SQLite, see https://www.prisma.io/docs/orm/reference/prisma-client-reference#createmany
However, note that:
If this is why you aren't seeing the function, there's good news: