WaspW
Wasp2y ago
OrBlatt

missing an opposite relation field

In a marketplace app, I have a JobAd entity that is created by an owner of type User. At some point in time after posting the JobAd, another User locks herself as the provider for this JobAd.
I believe the entity definition should be

entity JobAd {=psl
id Int @id @default(autoincrement())
description String
price Float
isDone Boolean @default(false)
createdAt DateTime @default(now())
owner User @relation(name: "createdBy", fields: [ownerId], references: [id])
ownerId Int
provider User? @relation(name: "servedBy", fields: [providerId], references: [id])
providerId Int?
psl=}

entity User {=psl
id Int @id @default(autoincrement())
isProvider Boolean @default(false)
jobAds JobAd[]
psl=}

However, when I run wasp db migrate-dev, I get the following error P1012
Error validating field jobAds in model
User
: The relation field jobAds on model
User
is missing an opposite relation field on the model JobAd. Either run prisma format or add it manually.
Error validating field owner in model JobAd: The relation field owner on model JobAd is missing an opposite relation field on the model
User
. Either run prisma format or add it manually.
Error validating field provider in model JobAd: The relation field provider on model JobAd is missing an opposite relation field on the model
User
. Either run prisma format or add it manually.

How can I fix it?
Was this page helpful?