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.
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.