2 years ago
#34121
josedguti
invalid Prisma.create() invocation
im trying to make a web app where I can create projects and inside those projects add requirements. Im good on the creating projects part but im having issues creating requirements for each project, maybe you guys can give a hand with this..
This is how my schema.prisma looks like
model Project {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
requirements Requirement[]
}
model Requirement {
id Int @id @default(autoincrement())
content String
notes Note[]
estimates Estimate[]
projectId Int
project Project @relation(fields: [projectId], references: [id])
}
model Note {
id Int @id @default(autoincrement())
content String
createdAt DateTime @default(now())
requirement Requirement? @relation(fields: [requirementId], references: [id])
requirementId Int?
}
model Estimate {
id Int @id @default(autoincrement())
content String
createdAt DateTime @default(now())
requirement Requirement? @relation(fields: [requirementId], references: [id])
requirementId Int?
}
and here is the code where I create a requirement for a project
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
export default async (req, res) => {
const data = JSON.parse(req.body)
console.log(data)
const createdRequirement = await prisma.requirement.create({
data: {
content: data.content,
project: {
connect: {
id: data.projectId,
}
}
}
})
res.json(createdRequirement)
}
so when i try to create a requirement and i only type 'req' is the content field, this is the error i get in the terminal
{ content: 'req' }
wait - compiling /_error (client and server)...
error - Error:
Invalid `prisma.requirement.create()` invocation:
{
data: {
content: 'req',
project: {
connect: {
? id?: Int
},
? create?: ProjectCreateWithoutRequirementsInput | ProjectUncheckedCreateWithoutRequirementsInput,
? connectOrCreate?: {
? where: ProjectWhereUniqueInput,
? create: ProjectCreateWithoutRequirementsInput | ProjectUncheckedCreateWithoutRequirementsInput
? }
}
}
}
Argument data.project.connect of type ProjectWhereUniqueInput needs at least one argument. Available args are listed in green.
Note: Lines with ? are optional.
So yeah, i dont know what im missing or if my schema doesnt make sense, I would appreciate some help...thank you!!
mysql
next.js
prisma
prisma2
0 Answers
Your Answer