The field in where clause of the upsert query should be unique.
In this case, the email field is not unique due to which you are getting this error.
Updating schema file by adding @unique attribute to the email field will solve the issue.
model prismaUser {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
email String @unique @db.VarChar(255)
profileViews Int
role String @db.VarChar(255)
}
Answer from Nurul Sundarani on Stack OverflowInvalid `prisma.***.upsert()` invocation in ...
upsert error when undefined field
Error with multiple upsert in $transaction
Incorrect logging for `upsert` error with `Infinity`
I have a question about nested upserts and if they're even possible.
I have a Prisma create that's working as expected;
An orders (table) can create an array of artwork (table), and the artwork can create an array of shirts (table).
The issue is when I want to update the shirts table through the order, similar to the create, with an upsert.
This block works as expected.
const CREATE = await prisma.orders.create({
data: {
artwork: {
create: artwork.map(art => {
return {
notes: art.notes,
shirts: {
create: art.shirts.map(shirt => ({
name: shirt.name,
url: shirt.url,
})),
},
};
})
}
},
});This block works to upsert the artwork, but fails when trying to upsert the shirts.
const UPDATE = await prisma.orders.create({
data: {
artwork: {
upsert: artwork.map(art => {
const updatedArtworkWithShirts = {
notes: art.notes,
shirts: {
upsert: art.shirts.map(shirt => {
const updatedShirt = {
name: shirt.name,
url: shirt.url,
};
return {
where: { id: shirt.id },
update: updatedShirt,
create: updatedShirt,
};
}),
},
};
return {
where: { id: art.id },
update: updatedArtworkWithShirts,
create: updatedArtworkWithShirts,
};
}),
},
}
});The error I'm receiving is:
Unknown arg `upsert` in data.artwork.upsert.0.create.shirts.upsert for type shirtsCreateNestedManyWithoutArtworkInput. Did you mean `select`?
Any thoughts? Am I approaching this incorrectly?