"Property does not exist" when I want to use model added in Prisma.schema
Asked Answered
S

14

33

I'm working on ReactJS project with NextJS Framework and Prisma to manage connection and queries to the DB.

On my local project the Support model is found and when I use it in my API and build my project it's ok.

But when I push my project on production server (Plesk), the build shows me this typescript error because it doesn't find the Support model:

./src/pages/api/support/index.ts:27:26
Type error: Property 'support' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'.

The path ./src/pages/api/support/index.ts is where I want to use the Support model

My prisma.schema:

datasource db {
  provider = "mysql"
  url      = env("DATABASE_CONNECTION")
}

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

model User {
  id              Int       @id @unique @default(autoincrement())
  gender          String?
  firstName       String
  lastName        String
  email           String    @unique
  phone           String
  birthday        DateTime?
  income          Float?
  pincode         Int?
  points          Float?
  token           String    @db.Text
  ipAddress       String
  kyc             Kyc[]
  createdAt       DateTime  @default(now())
  updatedAt       DateTime?
  isValidated     Boolean   @default(false)
  roleId          Int
  role            Role      @relation(fields: [roleId], references: [id])
  Alerts          Alerts[]
  Support Support[]
}

model Kyc {
  id        Int       @id @unique @default(autoincrement())
  name      String
  validated Boolean   @default(false)
  path      String
  createdAt DateTime  @default(now())
  updatedAt DateTime? @updatedAt
  user      User      @relation(fields: [userId], references: [id])
  userId    Int
}

model Alerts {
  id         Int      @id @unique @default(autoincrement())
  type       TYPE     @default(NOBLOCKED)
  message    String   @db.Text
  transferId Int      @unique
  fromUserId Int
  read       Boolean  @default(false)
  createdAt  DateTime @default(now())
  user       User     @relation(fields: [fromUserId], references: [id])
}

model Role {
  id   Int    @id @unique @default(autoincrement())
  name String
  User User[]
}

model Support {
  id        Int     @id @unique @default(autoincrement())
  subject   String
  message   String  @db.Text
  createdAt DateTime  @default(now())
  userId          Int
  user            User      @relation(fields: [userId], references: [id])
}

enum TYPE {
  BLOCKED
  NOBLOCKED
}

I don't know if I need to use prisma migrate dev or prisma migrate deploy each time I push the latest changes.

Sailer answered 21/9, 2021 at 19:22 Comment(7)
Did you ran prisma generate to generate Prisma client after making changes on Prisma schema ? prisma migrate dev will also generate Prisma client along with migration.Schizogenesis
In addition to what @PasinduDilshan mentioned (which is a likely cause of the problem), is this issue only with the Support model? Do all other models work as expected?Ciaphus
@TasinIshmam yes every other models worked properly. This error has been only for Support model because I had already pushed news models to the production server and I never had this type of error. This could be because I just started to use prisma migrate deploy with this Support model. And this is exactly what @Pasindudilshan said with the prisma migrate dev which also generates Prisma client and why I never had this error before.Sailer
Yes, prisma migrate deploy does not generate the client, so you have to run prisma generate as was mentioned. Just to clarify, you have been able to solve the problem now?Ciaphus
Yes everything works fine ! Thanks you guys for your help !Sailer
Also If you use VS Code sometimes you need to restart TS server,,Mantle
If anyone has this issue in WebStrom/IntelliJ: add a new JS library pointing to node_modules/@prisma/client in IDE settings (Languages & Frameworks -> JavaScript -> Libraries -> Add...)Chabot
C
93

I tried prisma generate and prisma migrate dev but was still having the same error. I had to restart VSCode and everything is working fine now

Consumer answered 19/2, 2022 at 8:20 Comment(4)
If you are using Typescript, open up the Command Palette (Ctrl Shift P), and typing "Restart Typescript Server", and press enter. Would help as well, without the need to restart VSCodeInterjoin
I remember that I had the same problem and fixed it with that, but now it doesn't work anymore on any device after restarts and it won't build, so not a vscode issue this time. What now??Luckily
running $ prisma generate worked for me. I read through the documentation and ideally prisma generate should be executed every time you make changes in the prisma.schema file. Here's the reference prisma.io/docs/concepts/components/…Monogenesis
Or simply open the file ./node_modules/.prisma/client/index.d.tsHaugh
P
8

I forgot to await

const user = prisma.user.findUnique({ 
  where: {
    userId: authorUserId
  },
  select: {
    id: true
  }
})

but should be:

const user = **await** prisma.user.findUnique({ 
  where: {
    userId: authorUserId
  },
  select: {
    id: true
  }
})
Purpurin answered 12/6, 2022 at 15:32 Comment(0)
K
6

Restart your typescript server in VSCode CTRL + SHIFT + P then type: restart TS Server

Killie answered 26/12, 2022 at 23:45 Comment(1)
i'ts works perfect for meMaggie
M
4

I have restarted my Visual Studio code and it started working fine.

Materse answered 18/11, 2022 at 7:39 Comment(0)
D
4

Try to run npx prisma generate. The model should then be in the prisma client. However if not, try ctrl + P then type in > reload window in the vs code command palette and hit the reload window option. That should solve the issue

Dana answered 2/6, 2023 at 6:52 Comment(0)
M
2

used prisma generate command but still, the schemas were marked as red. I had to restart my web storm IDE to get it fixed.

Missi answered 14/9, 2022 at 18:19 Comment(0)
L
2

I tried everything, even reinstalling prisma client. What worked for me was recreating the migration.

Longer answered 1/5, 2023 at 6:13 Comment(0)
H
2

Simply open the file ./node_modules/.prisma/client/index.d.ts.

This file contains the types generated. Opening it instantly triggers typescript to update those types.

Haugh answered 27/5, 2023 at 12:41 Comment(0)
V
2

I made a silly mistake by extending PrismaClient class in

prisma.module.ts

export class PrismaModule extends PrismaClient {}

prisma.service.ts

@Injectable()
export class PrismaService extends PrismaClient {}
Vacuum answered 29/8, 2023 at 11:13 Comment(0)
M
1

My issue was that the prisma client references the model names but as camelCase, whereas they're defined in the schema using PascalCase. This threw me because most of my model names are single words so where I'd defined a model name like User in the schema and added @@map("user") to the definition, I had the impression that when I did something like await prisma.user.delete({ ... the model/ table name user was lowercase as a result of the @@map declaration, but it turns out it isn't, rather prisma takes the model name and makes the first letter lowercase, and hence why for my model name OTP (with @@map("otp)) I have to use it like prisma.oTP.delete({ ...

Monniemono answered 30/6, 2023 at 8:31 Comment(0)
M
1

stop the local server, run npx prisma generate, start the server again in order to generate the prisma model in /node_modules/.prisma/client/index.d.ts which contains property that can be accessed by prisma instance.

Mapp answered 27/11, 2023 at 17:17 Comment(1)
Thanks, this worked. Is there a way to avoid doing this? I know every platform and ecosystem has its quirks, but this is just as annoying as Python's package management systemsYearbook
P
0

In my case, I created a schema named Post, but I called await prisma.posts. It should be called await prisma.posts. Make sure you don't make Typo. 😅

Portie answered 26/5, 2022 at 7:5 Comment(0)
E
0

Note! I'm only refer to the title of the question and not to the content. This error also can be raised also when you don't working with the right node version like in situation when using nvm with old node version.

Emblaze answered 15/6, 2022 at 15:49 Comment(0)
N
0

Just Restart VSCode, it works magic!!!.

if above solution not worked, try this solution

Nigger answered 16/5, 2023 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.