New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upsert errors with compound unique key with Date on MySQL: Query ... is required to return data, but found no record(s)
#12783
Comments
This comment was marked as outdated.
This comment was marked as outdated.
In general, In my case, I used the Side note: I must admit that having some experience with Java, Hibernate, and |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Very easy to reproduce. Using the data from the first post: generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model UserActiveHistorySummary {
summary_date DateTime @db.Date
user_id String @db.VarChar(255)
login_count Int @default(0)
created_at DateTime @default(now()) @db.DateTime(0)
updated_at DateTime @default(now()) @db.DateTime(0)
@@unique([summary_date, user_id], map: "uq_uahs_summary_date_user_id")
@@index([summary_date, login_count], map: "idx_uahs_summary_date_login_count")
@@index([summary_date], map: "idx_uahs_summary_date")
@@index([user_id], map: "idx_uahs_user_id")
@@map("user_active_history_summaries")
} import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient({
log: ['query', 'info', 'warn', 'error'],
})
async function main() {
const data = await prisma.userActiveHistorySummary.upsert({
where: {
summary_date_user_id: {
summary_date: '2022-03-29T00:00:00+09:00',
user_id: 'shimizu_test',
},
},
create: {
summary_date: '2022-03-29T00:00:00+09:00',
user_id: 'shimizu_test',
login_count: 3,
},
update: {
login_count: 7,
},
})
console.log(data)
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
|
Following up on some details: @dimw Thanks for these details! Can you maybe share a similar simplified example to what you are doing as what @hirasaki1985 did? That would help us to also rerun this - and then at least use it to test our fix of this issue. Potentially it will also show us a variant, that we might otherwise miss. @Peter-Sparksuite Can you maybe do the same? Schema and @Simonpedro Are you really getting the same @tlantli Did you also get this exact error message? Can you share your Thanks all. (Internal discussion: https://prisma-company.slack.com/archives/C040N0UADF0/p1662665811153459) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
It's not unique to upserts, happens on creates as well. Here's a distilled repro based on @pimeys code: schema.prisma generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model UserActiveHistorySummary {
summary_date DateTime @db.Date
user_id String @db.VarChar(255)
@@id([summary_date, user_id]) // or @@unique
} index.js import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient({
log: ["query", "info", "warn", "error"],
})
async function main() {
const data = await prisma.userActiveHistorySummary.create({
data: {
summary_date: "2022-03-29T00:00:00+09:00",
user_id: "test",
},
})
console.log(data)
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
}) |
Internal note 🌯 : I am recategorizing this as "Date/Time related" from "Concurrency". It is still unclear if that applies to all people that have posted above, but the error message points more to that (so potentially some people were just in the wrong issue here). |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
upsert is required to return data, but found no record(s).
Query ... is required to return data, but found no record(s)
Query ... is required to return data, but found no record(s)
Query ... is required to return data, but found no record(s)
@Peter-Sparksuite From your description the problem does not have the same properties as the one we are investigating here - it would need a Date like column in the primary key to be explained. We will fix that problem, and then close this issue. Please open a new issue and provide some more information what exactly is happening for you. Thanks. Thanks @ulevitsky - that allowed me to connect some dots. We are now treating these 3 issues (this and the 2 ones I linked) as 1 problem and will try to fix it. @tlantli I think your problem is more similar to #10497 with the trigger. Please leave a comment there. Thanks. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I found this was addressed by stripping the milliseconds out of my time:
I'm guessing because my DB model doesn't have milliseconds:
|
Same issue when using Schema:
Create call:
Error message:
|
Hi @AndreyMarchuk there is a known regression with |
Note: It's not in a dev version yet, we'll keep you updated with a version you could try 🔜 |
|
@tomhoule cannot reproduce the issue anymore, all good |
Not fixt for mssql. Problem stil exist on 4.6.0-dev.42 |
@KnutHelstad Thanks for checking on a dev version. It could be that your issue is different from what was posted here. Could you provide more info / reproduction material (query / schema for example). |
OK. I can open a new issue. |
Discussed in #12730
Originally posted by hirasaki1985 April 8, 2022
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
source code
console error
generated table schema.
package.json
The text was updated successfully, but these errors were encountered: