如何在prisma中过滤关系数据?

问题描述 投票:0回答:1

我收到错误:

→ 60 所常量学校 =等待 this.prisma.school.findMany( 当前数据库中不存在

t4.id
列。

只有当我删除

line:214-216
时,错误才会消失。但我无法删除这些行,因为我想过滤
semesters

const schools = await this.prisma.school.findMany({
  where: {
    semesters: {
      some: {
        isActive: true,
        subjects: {
          none: {},
        },
      },
    },
  },
  select: {
    id: true,
    name: true,
    semesters: {
      where: {
        isActive: true,
        subjects: { // line:214
          none: {}  // line:215
        }           // line:216
      },
      select: { id: true, subjects: { select: { id: true } } },
    },
  },
  take: 100,
});

我知道可以通过以下方式完成,但我更喜欢上面的过程。

const schools = ...

const filteredSchools = schools.map(...).filter(...);
prisma
1个回答
0
投票

如果您收到类似于

The column XXX does not exist in the database
的错误,则说明您的 Prisma 客户端与数据库不同步。您可能已向模型添加了
id
列,或向 Prisma 架构添加了全新的模型。但它尚未在您的数据库中,因此出现错误。

尝试运行 Prisma migrate 命令来生成并针对数据库执行必要的迁移,这样两者就会同步。

npx prisma migrate dev

每次修改 Prisma 架构时都必须运行此命令。

文档:https://www.prisma.io/docs/orm/prisma-migrate/workflows/data-migration

© www.soinside.com 2019 - 2024. All rights reserved.