简体   繁体   English

如何解决此错误(Nest & Prisma):错误 [ExceptionsHandler] 无法读取未定义的属性(读取“organ”)

[英]How to solve this error (Nest & Prisma): ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'organ')

I'm developing an API using Nestjs and Prisma, the problem occurs when I try to insert information in the Database (Postgres), I get this error, saying that it cannot read the "organ" property which is the table in which I intend to insert the information.我正在使用 Nestjs 和 Prisma 开发一个 API,当我尝试在数据库 (Postgres) 中插入信息时出现问题,我得到这个错误,说它无法读取我想要的表的“organ”属性插入信息。

The error is occurring in the repository in the create method: `错误发生在存储库中的创建方法中:`

import { Organ } from '@prisma/client';
import { CreateOrganDto } from '../../../../../modules/organs/dto/create-organ.dto';
import { IOrganRepository } from '../../../../../modules/organs/repositories/IOrganRepository';
import { PrismaService } from '../../../../../shared/infra/db/prisma.service';

export class OrganRepository implements IOrganRepository {
  constructor(private prisma: PrismaService) {} 

  async create({ name }: CreateOrganDto): Promise<Organ> {
    const organ = await this.prisma.organ.create({
      data: {
        name
      },
    });

    return organ;
  }

  async findByName(name: string): Promise<Organ | null> {
    const organ = await this.prisma.organ.findUnique({
      where: {
        name,
      },
    });

    return organ;
  }
}

` `

a const organ dev const 器官开发者

this.prisma.organ.create method is returning an Organ, never type when it should just return Organ

It looks like the PrismaClient is not in sync with Prisma Schema.看起来 PrismaClient 与 Prisma Schema 不同步。 You would need to invoke npx prisma generate in order to regenerate the PrismaClient - Reference .您需要调用 npx npx prisma generate才能重新生成 PrismaClient- Reference

Also, I would recommend checking that all models defined in schema file has been created in the database, you can either use npx prisma migrate dev or npx prisma db push to create the corresponding tables - Reference .此外,我建议检查模式文件中定义的所有模型是否已在数据库中创建,您可以使用npx prisma migrate devnpx prisma db push创建相应的表 - Reference

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该如何解决这个错误&#39;无法读取未定义的属性(读取&#39;符号&#39;)&#39;在fastify上 - How can i solve this error 'Cannot read properties of undefined (reading 'sign')' on fastify 错误:无法读取未定义的属性(读取“主机”) - Error: Cannot read properties of undefined (reading 'host') 错误:无法读取未定义的属性(读取“管理员”) - Error: Cannot read properties of undefined (reading 'admin') 如何修复类型错误:无法读取未定义的属性(读取“0”)? - How to fix the Type Error: Cannot read properties of undefined (reading '0')? Prisma 种子 - 无法读取未定义的属性(读取“findFirst”) - Prisma seed - cannot read properties of undefined (reading 'findFirst') 如何解决这个无法读取未定义的属性(读取“cookies”) - How to solve this Cannot read properties of undefined (reading 'cookies') 笑话错误:TypeError:无法读取未定义的属性(读取“发送”) - Jest error: TypeError: Cannot read properties of undefined (reading 'send') discord.js 错误:无法读取未定义的属性(读取“客户端”) - discord.js error: Cannot read properties of undefined (reading 'client') 错误 TypeError:无法读取未定义的属性(读取“_id”) - ERROR TypeError: Cannot read properties of undefined (reading '_id') 收到错误“无法读取未定义的属性(读取'id')” - Getting an error "Cannot read properties of undefined (reading 'id') "
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM