Property 'job' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'

Issue

I’m using Expressjs as a backend and also using Prisma to work with a database, and also using TypeScript, and following this article.

I’m getting this type error Property 'job' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'

My code is

import { PrismaClient } from '@prisma/client';
import app from './app';

const prisma = new PrismaClient();

app.post('/job', async (req, res) => {
  const job = await prisma.job.create({ data: req.body });
  res.json(job);
});

app.get('/', async (req, res) => {
  const job = await prisma.job.findMany();
  res.json(job);
});

The above error appears in here await prisma.job.create()

Here is the prisma.schema:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlserver"
  url      = env("DATABASE_URL")
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}

model Job {
  id       Int    @id @default(autoincrement())
  title    String
  location String
  salary   String
}

Please help, I’ll appreciate for this.

Solution

The given error:

Property ‘job’ does not exist on type ‘PrismaClient<PrismaClientOptions, never, RejectNotFound | RejectPerOperation | undefined>’

indicates that the prisma client is not aware of the given model Job/prisma.job. Meaning that the model definition
has been added after the prisma client was generated.
Prisma itself works by internally generating types for the given models and extending it’s client programmatically
which means that we have to regenerate the client everytime we make changes to the model so it becomes aware of said
changes.
To regenerate the client the prisma cli provides us with the generate command which can be executed like
so: npx prisma generate.

Answered By – Palladium02

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published