Hey! I’m struggling with a strange error creating ...
# prisma-client
t
Hey! I’m struggling with a strange error creating a new item in a collection that I can’t seem to find anything on. Best explained with my schema files, the failing create call, and the errors that ensue. Here’s my schema for the idea of a ‘report’, which has to belong to a ‘team’.
Copy code
model Report {
  id            String        @id @default(auto()) @map("_id") @db.ObjectId
  ...
  team          Team          @relation(fields: [teamId], references: [id])
  teamId        String 
  ...
}
Here’s the Team:
Copy code
model Team {
  id                   String             @id @map("_id")
  ...
  reports              Report[]
  ...
}
I’ve tried creating a number of different ways. I thought the right way was as such:
Copy code
const report = await prisma.report.create({
        data: {
            id : newId.toString(),
            teamId:        teamId,
            ...
        },
    });
Which gives error:
Copy code
"Parse errors: [Query parsing/validation error at Mutation.createOneReport.data.ReportCreateInput.team: A value is required but not set"
Which I interpret to mean it’s missing the ‘team’ object. So I tried:
Copy code
const report = await prisma.report.create({
        data: {
            id : newId.toString(),
            ...
            teamId:        teamId,
            team: {
                connect: {
                    id: teamId,
                },
            },
            ...
        },
    });
Which errors out telling me I shouldn’t be including team Id. (will include error in thread). But if I don’t invlude teamId it errors out telling me I should be using teamId. Very confusing since I used to be able to just add teamId in these types of situations
✅ 1
To summarize: 1. Create with just a referencing teamId, it tells me I am missing the Team object. 2. If I create it while connecting the Team Object it tells me I shouldn’t be including the teamId string 3. If I take out the teamId string it tells me I’m missing it. Error 2. :
Copy code
A value is required but not set., Query parsing/validation error at `Mutation.createOneReport.data.ReportUncheckedCreateInput.teamId`
Error for scenario 3:
Copy code
Unknown arg `teamId` in data.teamId for type ReportCreateInput. Did you mean `team`?
Solved — it ended up just being an inaccurate error message. There was another parameter in report that was being set to null. WIll keep this up in case it’s leading to confusing error messages in similar cases