PRISMA:更新方法中的 where 子句出现类型错误

PRISMA: Getting type error on where clause in update method

有一个特定的 Prisma ORM 库错误需要帮助。

我创建了一个迁移并将其推送到 postgres 数据库。

我已经为 Prisma 生成了客户端模型,并且能够使用 create 方法查找和插入数据。

我遇到问题的地方是更新方法。

这是我的代码

app.post("/articles/:title", async (req: Request, res: Response) => {
  const article = await prisma.article.update({
    where: { title: req.params.title },
    data: { title: req.body.title, content: req.body.content },
  })
  res.send('The article was posted sucessfully.' + article)
})

我收到以下错误,这让我认为客户端在使用 where 参数时没有找到类型 'title'。

app.ts:65:14 - 错误 TS2322:类型 '{ title: string; }' 不可分配给类型 'ArticleWhereUniqueInput'。 Object 字面值只能指定已知属性,'title' 类型不存在 'ArticleWhereUniqueInput'。

65 其中:{ 标题:req.params.title }, ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.prisma/client/index.d.ts:784:3 第784话 ~~~~~ 预期类型来自 属性 'where' ,它在此处声明为类型 'Subset<ArticleUpdateArgs, ArticleUpdateArgs>'

还有其他人遇到过这个问题吗? 我试图反省数据库以确保数据库完全按原样捕获,包含标题和内容字段,然后再次生成客户端。

非常感谢 詹姆斯

找到答案: answer was a response from Antonie

中的字段
  • 哪里

必须是唯一的。

如果你可以创建一些字段,比如日期@unique(日期:DateTime!@unique),并将其用于更新插入中的位置,我认为它会起作用(在我的本地测试)。