Hey @hirasaki1985 👋 ,

I reproduced this on my end as well (using MySQL) and it does seem unexpected. I'm going to convert this discussion into an issue where our engineering teams will pick it up for investigation.

🌐
Prisma
prisma.io › home › prisma client api › prisma client api › prisma client api
Prisma Client API | Prisma Documentation
The following query has multiple unique values in the where clause, so Prisma Client does not use a database upsert:
🌐
Prisma
prisma.io › home › crud › crud › crud › crud
CRUD (Reference) | Prisma Documentation
const upsertUser = await prisma.user.upsert({ where: { email: "viola@prisma.io" }, update: { name: "Viola the Magnificent" }, create: { email: "viola@prisma.io", name: "Viola the Magnificent" }, });
Discussions

upsert does not working with multi unique key.
Hi, there. I have a error. I tried to use upsert function with the multi @@unique key. Could you please tell me how to deal with it? schema.prisma model UserActiveHistorySummary { summary_date Date... More on github.com
🌐 github.com
4
2
node.js - How to upsert new record in Prisma without an ID? - Stack Overflow
I thought I could do that with upsert method provided by Prisma and available in the generated client, but the where clause of that method only works with id (or @unique fields), but if the record doesn't exist, there isn't any id to provide. More on stackoverflow.com
🌐 stackoverflow.com
node.js - Prisma: Update using "where" with non-unique fields? - Stack Overflow
Is this at all possible with Prisma or do I need a separate query for this that retrieves the instance? ... In this case, you would need to use updateMany as you are using a non-unique field along with the unique one. More on stackoverflow.com
🌐 stackoverflow.com
.upsert when no way to track query/track unique identifier?
} I guess my question is 2 fold: 1) Can I use upsert/this design database? Or do I need to rethink my approach. 2) If I can make this work, what's the correct way to resolve this. ... From what I understand, older versions of Prisma only expose unique fields (see the type UserWhereUniqueInput) ... More on answeroverflow.com
🌐 answeroverflow.com
March 18, 2023
🌐
Prisma
prisma.io › home › working with compound ids and unique constraints › working with compound ids and unique constraints › working with compound ids and unique constraints › working with compound ids and unique constraints
Working with compound IDs and unique constraints (Concepts) | Prisma Documentation
A compound ID or compound unique constraint may be used in the where filter of an update query: const like = await prisma.like.update({ where: { likeId: { userId: 1, postId: 1, }, }, data: { postId: 2, }, }); They may also be used in the where ...
🌐
DEV Community
dev.to › dailydevtips1 › how-to-perform-non-updating-upserts-in-prisma-4e3a
How to perform non updating upserts in Prisma - DEV Community
October 28, 2021 - It takes a where a query that should query on a unique field. Then it comes with both the update and create functions like so: const playlist = await prisma.playlist.upsert({ where: { uri: uri, }, update: {}, create: playlistItem, });
🌐
Daily Dev Tips
daily-dev-tips.com › posts › how-to-perform-non-updating-upserts-in-prisma
Non-updating Upserts in Prisma [2024]
February 5, 2024 - The Prisma upsert command takes a where-query. Where-queries should query a unique field in the DB.
🌐
Onebite
onebite.dev › prisma-error-when-doing-upsert
Prisma error when doing upsert
February 3, 2023 - When implementing upsert through Prisma you need to make sure that the where clause contains a unique column only
Find elsewhere
🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
const result = await prisma.post.update({ where: { id: 6, }, data: { author: { upsert: { create: { email: "bob@prisma.io", name: "Bob the New User", }, update: { email: "bob@prisma.io", name: "Bob the existing user", }, }, }, }, include: { author: true, }, });
🌐
GitHub
github.com › prisma › prisma › discussions › 5929
upsert where @@unique([id1, id2]) create missing relationship attributes as connect · prisma/prisma · Discussion #5929
Looks like when you use a upsert with a where that uses a @@unique([]) the create will not allow attaching connections for belongsTo and hasMany..... model Trigger { id String @id @default(cuid()) funnel Funnel @relation(fields: [funnelId], references: [id]) funnelId String product Product @relation(fields: [productId], references: [id]) productId String variants Variant[] @@unique([funnelId, productId]) } return await context.prisma.trigger.upsert({ where: { funnelId_productId: { funnelId: localFunnelId, productId: localProductId, }, }, create: { funnel: { connect: { id: localFunnelId } }, pr
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 22897
Prisma.upsert() should support the value of null in where condition with unique key · prisma/prisma · Discussion #22897
January 31, 2024 - Prisma Client requires a unique condition to pin exactly one record in the database for the upsert() operation. This is because upsert() is designed to operate on a single record, either updating it if it exists or creating it if it does not.
Author   prisma
🌐
Answer Overflow
answeroverflow.com › m › 1086787706497028136
.upsert when no way to track query/track unique identifier? - Theo's Typesafe Cult
March 18, 2023 - } I guess my question is 2 fold: 1) Can I use upsert/this design database? Or do I need to rethink my approach. 2) If I can make this work, what's the correct way to resolve this. ... From what I understand, older versions of Prisma only expose unique fields (see the type UserWhereUniqueInput) on your models as fields in the where object when upsert is being used.
🌐
GitHub
github.com › prisma › prisma › discussions › 23887
Why is only a single unique column supported for upserts? · prisma/prisma · Discussion #23887
April 15, 2024 - The Prisma Client's upsert operation currently supports only one unique field in the where option. This means that if you have multiple unique fields in the where clause, Prisma Client will not use a database upsert.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 14584
upsert(): Unique constraint on DateTime sqlite · Issue #14584 · prisma/prisma
July 31, 2022 - model BusinessAnalytics { id String @id @default(cuid()) business Business @relation(fields: [businessId], references: [id]) businessId String startDate DateTime whatsappCount Int @default(0) phoneCount Int @default(0) emailCount Int @default(0) instagramCount Int @default(0) websiteCount Int @default(0) @@unique([businessId, startDate]) } export async function logBusinessAnalytics({ id, whatsapp, phone, email, instagram, website, }: Pick<Business, "id"> & AnalyticsMethods) { // Increments the count of the given method return prisma.businessAnalytics.upsert({ where: { businessId_startDate: { businessId: id, startDate: startOfWeek(new Date()).toISOString(), }, }, create: { businessId: id, whatsappCount: whatsapp ?
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 21853
`upsert()` fails on unique key when being used as "`findOrCreate`" with empty `update` field · Issue #21853 · prisma/prisma
November 8, 2023 - // empty update to use upsert as findOrCreate await this._prisma.user.upsert({ update: {}, create: { username, password, }, where: { username_password: { username, password, }, }, });
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 24888
Database upsert with composite unique constraint · prisma/prisma · Discussion #24888
However, for my upsert query, I'd need to use a where clause on the unique constraint id_profileViews as follows : prisma.user.upsert({ where: { id_profileViews: { id: 1 profileViews: 1 } }, create: { id: 1, profileViews: 1, userName: 'Alice', email: 'alice@prisma.io', }, update: { email: 'updated@example.com', }, })
Author   prisma