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.
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
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. You would need to invoke npx prisma generate
in order to regenerate the 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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.