P
Prisma5mo ago
kaushik.

Help me out with this pls

I am pretty new to Prisma and I still am unable to debug and solve this prisma code: Error:
Error: P1012

error: Error validating field `admin` in model `Admin`: The relation field `admin` on model `Admin` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.
--> schema.prisma:29
|
28 | id Int @id @default(autoincrement())
29 | admin User @relation(fields: [adminId], references: [id])
30 | adminId Int
|
error: Error validating field `question_testcases` in model `Question`: The relation field `question_testcases` on model `Question` is missing an opposite relation field on the model `TestCases`. Either run `prisma format` or add it manually.
--> schema.prisma:47
|
46 | question_points Int
47 | question_testcases TestCases[]
48 | question_author User @relation(fields: [authorId], references: [id])
|
error: Error validating field `question_author` in model `Question`: The relation field `question_author` on model `Question` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.
--> schema.prisma:48
|
47 | question_testcases TestCases[]
48 | question_author User @relation(fields: [authorId], references: [id])
49 | authorId Int
|
error: Error validating field `solved_by` in model `Question`: The relation field `solved_by` on model `Question` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.
--> schema.prisma:51
|
50 | attempted_by User[] @relation("attempted")
51 | solved_by User[] @relation("solved")
52 | submissions Submission[]
Error: P1012

error: Error validating field `admin` in model `Admin`: The relation field `admin` on model `Admin` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.
--> schema.prisma:29
|
28 | id Int @id @default(autoincrement())
29 | admin User @relation(fields: [adminId], references: [id])
30 | adminId Int
|
error: Error validating field `question_testcases` in model `Question`: The relation field `question_testcases` on model `Question` is missing an opposite relation field on the model `TestCases`. Either run `prisma format` or add it manually.
--> schema.prisma:47
|
46 | question_points Int
47 | question_testcases TestCases[]
48 | question_author User @relation(fields: [authorId], references: [id])
|
error: Error validating field `question_author` in model `Question`: The relation field `question_author` on model `Question` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.
--> schema.prisma:48
|
47 | question_testcases TestCases[]
48 | question_author User @relation(fields: [authorId], references: [id])
49 | authorId Int
|
error: Error validating field `solved_by` in model `Question`: The relation field `solved_by` on model `Question` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.
--> schema.prisma:51
|
50 | attempted_by User[] @relation("attempted")
51 | solved_by User[] @relation("solved")
52 | submissions Submission[]
4 Replies
RaphaelEtim
RaphaelEtim5mo ago
Hi @kaushik. Most of the error is because the models do not have back relations. See the documentation for creating relations.
Relations (Reference) | Prisma Documentation
A relation is a connection between two models in the Prisma schema. This page explains how you can define one-to-one, one-to-many and many-to-many relations in Prisma.
RaphaelEtim
RaphaelEtim5mo ago
I have update the code and shared with you
kaushik.
kaushik.OP5mo ago
Thank you so much! I am glad I joined here :D
RaphaelEtim
RaphaelEtim5mo ago
I'm glad i could be of help. Feel free to ask any questions that come to mind.
Want results from more Discord servers?
Add your server