Reputation: 57
Trying to update a field from the table where the table is connected with other tables also. But showing the error here. "An operation failed because it depends on one or more records that were required but not found. Record to update not found."
const deleteBook = await prisma.aca_book_list.update({
where: {
id: productId,
},
data: {
is_active: false,
}
})
await BasicResponse(res, 1, 'Book Deleted', deleteBook)
if (!deleteBook) {
await BasicResponse(res, 0, 'Book Not Found to Delete', [])
return
}
Upvotes: 2
Views: 13376
Reputation: 1314
I faced this issue trying to insert a record in the database. This record had a relation set to another table, but the "foreign key" passed to the record did not map to a record in the relation table.
For example:
User {
id String
postIds String[]
posts Posts[]
}
Post {
id String
userId String
User User
}
Now if you try to insert a Post
with a userId
that doesn't exist, you'll see the error.
Upvotes: 1
Reputation: 187
Prisma throws those errors when they can't find matching data.
But if you use "updateMany" instead of "update", you will not meet these errors.
Because when you use "update", Prisma run the "select" query first and runs the "update" query
So if they don't get any data when they run the "select" query, they throw the error.
But if you use "updateMany", Prisma doesn't run the "select" query, runs just the "update" query only.
Upvotes: 10