0

I have 3 Prisma2 tables where User can have lots of Sheet and only one Doc

model User {
  id Int @default(autoincrement()) @id
  firstName String
  lastName String
  email String @unique
  sheets Sheet[]
  docs Doc?
}
model Sheet {
  id Int @default(autoincrement()) @id
  user_sheets Int
  User User @relation(fields: [user_sheets], references: [id])
  sheetName String
}
model Doc {
  id Int @default(autoincrement()) @id
  user_doc Int?
  User User? @relation(fields: [user_doc], references: [id])
  docName String
}

I am using Prisma2 Client like this to get all sheets and docs of the user with specific email id:

  import { PrismaClient } from '@prisma/client'
  const prisma = new PrismaClient();
  const users = await prisma.user.findMany({
            where: {
              email: email
            },
            include: {
                sheets: true,
                docs: true,
            }
        });

I have already done migrate-save, migrate-up and generate

The error I am getting is this:

PrismaClientValidationError: 
Invalid `prisma.user.findMany()` invocation in
webpack-internal:///./pages/api/resume.js:12:47

{
  include: {
    sheets: true
    ~~~~~~
    docs: true
    ~~~~~~
  }
}


Unknown field `sheets` for include statement on model User.
This model has no relations, so you can't use include with it.

Please help me understand and resolve it as I used the prisma2 doc as well as followed this tutorial: https://www.youtube.com/watch?v=jeHJbYLCgzI

but with no luck the error continues to haunt me.

rohitpaniker
  • 695
  • 1
  • 7
  • 25
  • Hmm, this is weird! The schema looks like it should allow for that query. Just a hunch, but maybe try `rm -rf node_modules` and then re-install the dependencies with `npm install`. Sometimes Prisma Client might not be properly updated after a schema change... – nburk Nov 09 '20 at 19:05
  • If the issue persists, I'd recommend that you [open an issue on GitHub](https://github.com/prisma/prisma/issues) because then it could be a bug that you're hitting. – nburk Nov 09 '20 at 19:06
  • 1
    @nburk Thank you for your time looking in to this, I found the problem. When you said reinstalling node_modules, I stopped the server and re ran the command ```yarn run dev``` and the problem got resolved. My mistake was I was not stopping the server and starting again after the ```yarn generate``` command would generate Prisma Client. – rohitpaniker Nov 09 '20 at 19:33
  • Sounds good, glad to hear you could resolve this! :) – nburk Nov 09 '20 at 20:09

1 Answers1

5

Issue Resolved Update

After I do prisma migrate save, prisma migrate up and prisma generate, I stopped the server running via terminal and restarted the server after which the model started working. Figured the issue was due to not restarting the server again after Prisma generates a client using new migrations.

Big thank you to @nburk for possible suggestions.

rohitpaniker
  • 695
  • 1
  • 7
  • 25