@ridhwaans 👋

delete will always throw an exception so it's best to handle it via try/catch to keep it to a single query.

Discussions

Support `deleteIfExists()` and nested `deleteIfExists`
Record to delete does not exist. await prisma.user.update({ where: { id: 43, }, data: { name: "foo", profile: { delete: true, }, }, }); // An operation failed because it depends on one or more records that were required but not found. More on github.com
🌐 github.com
14
September 27, 2021
new guy with wierd error when deleting a record trough prisma studio
i got this message when deleting a record. same thing happens with prisma postgres. More on answeroverflow.com
🌐 answeroverflow.com
April 5, 2025
node.js - Prisma not deleting because it depends on nonexistent record - Stack Overflow
I'm using Prisma with an Express backend and React frontend. Testing my delete request on Postman, I get this error: "\nInvalid prisma.user.delete() invocation:\n\n\n An operation failed bec... More on stackoverflow.com
🌐 stackoverflow.com
Error on delete with zero records
Record to delete does not exist. Shouldn't it simply complete successfully affecting 0 records? This forces us to perform a count operation first and only proceed if it's > 0. I've noticed this behaviour on Postgres. ... Thank you for raising this question. The behavior you're experiencing is indeed how Prisma ... More on github.com
🌐 github.com
2
1
🌐
DEV Community
dev.to › mshidlov › how-to-fix-the-record-to-delete-does-not-exist-error-in-prisma-5fo3
How to Fix the “Record to Delete Does Not Exist” Error in Prisma - DEV Community
January 14, 2025 - Record to delete does not exist. In plain English, this means Prisma can’t find the record you’re trying to delete because your where clause does not match a unique key. Below, we’ll walk through how this happens and the steps to fix it, using a blog post example model. ... the where clause must reference a unique key—e.g., a primary key (@id), a field marked with @unique, or a group of fields defined with @@unique([...]) or @@id([...]) (a composite key). If you include fields that aren’t guaranteed to be unique, Prisma won’t find (or won’t allow) the record because it doesn’t match the unique constraint, triggering the “Record to delete does not exist” error.
🌐
GitHub
github.com › prisma › prisma › issues › 9460
Support `deleteIfExists()` and nested `deleteIfExists` · Issue #9460 · prisma/prisma
September 27, 2021 - await prisma.profile.deleteIfExists({ where: { id: 42, }, }); await prisma.user.update({ where: { id: 43, }, data: { name: "foo", profile: { deleteIfExists: true, }, }, }); As an alternative, we can use deleteMany, but it is verbose.
Author   prisma
🌐
Answer Overflow
answeroverflow.com › m › 1358107026173071452
new guy with wierd error when deleting a record trough prisma studio - Prisma
April 5, 2025 - Prisma 6.14 "Invalid prisma.parentChild.findMany()" error while deleting child record ·
Top answer
1 of 2
3

You have a one to one relation and you may want to delete the Volunteer when you delete the related User (but that depends on what you want to do). If it is the case, you can add onDelete: Cascade when specifying your relation :

model User {
  id           String      @id
  email        String      @unique
  firstName    String
  lastName     String
  approved     Boolean     @default(false)
  usersDb      Boolean     @default(false)
  volunteersDb Boolean     @default(false)
  createdAt    DateTime    @default(now())
  updatedAt    DateTime    @updatedAt
  avatarUrl    String?     @default("")
  isActive     Boolean     @default(true)
  lastLoggedIn DateTime    @default(now())
  role         String      @default("viewer")
  volunteer    Volunteer[]
}

model Volunteer {
  id                       String   @id @default(uuid())
  userId                   String
  dbUser                   User     @relation(fields: [userId], references: [id], onDelete: Cascade)

Then, when you will delete a user, the corresponding Volunteer will be automatically deleted too.

See documentation for possible actions : https://www.prisma.io/docs/concepts/components/prisma-schema/relations/referential-actions

2 of 2
2

I figured this out and wanted to share. I was right, this had everything to do with the relation I'd created between the User and Volunteer table. When I tried to delete a record from the User table, I didn't tell Prisma what to do with the related records, so I got that error. I went back to my Volunteer model and made the relation fields optional, and the delete request worked. Here's the documentation on this, and here's my updated schema:

model User {
  id           String      @id
  email        String      @unique
  firstName    String
  lastName     String
  approved     Boolean     @default(false)
  usersDb      Boolean     @default(false)
  volunteersDb Boolean     @default(false)
  createdAt    DateTime    @default(now())
  updatedAt    DateTime    @updatedAt
  avatarUrl    String?     @default("")
  isActive     Boolean     @default(true)
  lastLoggedIn DateTime    @default(now())
  role         String      @default("viewer")
  volunteer    Volunteer[]
}

model Volunteer {
  id                       String   @id @default(uuid())
  userId                   String?
  dbUser                   User?     @relation(fields: [userId], references: [id])
🌐
Tsnc
prismaphp.tsnc.tech › docs › delete
Delete - Prisma PHP
Throws an Exception if select and include are used together. Throws an Exception on any database or transaction error. use Lib\Prisma\Classes\Prisma; $prisma = Prisma::getInstance(); $deletedUser = $prisma->user->delete([ 'where' => ['id' => 'someUserId'], ]); echo "<pre>"; echo "Deleted User: " .
Find elsewhere
Top answer
1 of 1
4

Hi @rgaino 👋

Thank you for raising this question.

The behavior you're experiencing is indeed how Prisma currently operates. When you attempt to delete a record that doesn't exist using the delete method, Prisma throws an exception. This is because the delete method is designed to operate on a single record and expects that record to exist. If the record doesn't exist, it throws an error to indicate that the operation couldn't be completed as expected.

This behavior can be useful in scenarios where the absence of a record is an exceptional circumstance and should halt the execution of your code. However, it can indeed lead to additional database operations if you need to check for the existence of a record before attempting to delete it.

There have been discussions and open issues in the Prisma community about this behavior. For example, in this GitHub issue #10142, a user suggested adding updateOrThrow() and deleteOrThrow() methods to Prisma Client, which would throw an exception if the record to update or delete doesn't exist. In GitHub issue #9460, a user suggested adding a deleteIfExists method, which would delete a record if it exists and do nothing if it doesn't, without throwing an error.

As a workaround, you can use the deleteMany method instead of delete. The deleteMany method doesn't throw an error if no records are found that match the where clause. It simply returns a count of the records deleted, which would be 0 if no matching records were found.
Here's an example:

const deleteResult = await prisma.types.deleteMany({
  where: {
    bigserial: "non-existent id",
  },
});

In this case, deleteResult.count would be 0 if no records were found that match the where clause.

Please note that this is a workaround and might not be suitable for all use cases. Always consider the implications of using deleteMany instead of delete, especially in scenarios where deleting multiple records could have unintended side effects.

If this answers your question, it would be great if you could mark this Discussion as answered to indicate that it has been resolved.

Otherwise please let us know how else we can help you further or close the Discussion if it was resolved in some other way 🙏

🌐
This Dot Labs
thisdot.co › blog › how-to-implement-soft-delete-with-prisma-using-partial-indexes
How to Implement Soft Delete with Prisma using Partial Indexes - This Dot Labs
February 2, 2024 - So there are some caveats to implementing partial delete in this way. The first being that the schema doesn’t reflect the state of the database 1:1. Thankfully, Prisma doesn’t care about untracked indexes existing, but knowing the index exists requires looking in the migration files instead of the schema.
🌐
DEV Community
dev.to › martinratinaud › prisma-null-or-does-not-exists-443e
Prisma "null or does not exists" - DEV Community
August 28, 2023 - Created account quickly just to thank you, I was using Cursor pro with claude-3.7-sonnet-thinking and it couldn't figure it out, and prisma documentation wasn't helpful at all, thanks for sharing! ... SELECT acctuniqueid, username, callingstationid, framedipaddress FROM tiger.RadiusAcct WHERE username = ${element.login} AND acctstoptime IS NULL AND NOT EXISTS ( SELECT 1 FROM tiger.RadiusAcct subquery WHERE subquery.username = ${element.login} AND subquery.acctstoptime IS NOT NULL AND subquery.radacctid > tiger.RadiusAcct.radacctid ) ORDER BY radacctid DESC LIMIT 1;
🌐
RedwoodJS Community
community.redwoodjs.com › get help and help others
Views in prisma schema cause unit test scenarios to break - Get Help and Help Others - RedwoodJS Community
August 1, 2024 - Hey all, I’m using Redwood 6.6.4. I’ve got a test suite across our Redwood app that relies pretty heavily on scenarios. Recently, I used the “views” preview feature and added some db migrations with my Postgres views, and then added those views to the prisma schema.
🌐
Shopify Community
community.shopify.com › shopify apps
New app scaffold: Error: Prisma session table does not exist.
September 12, 2023 - I have run “npm init @Shopify_77 /app@latest” to scaffold a new app to become a new sales channel. However, the app generated does not work out of the box. I have already had to modify the shopify.web.toml file to add back in missing fields to get past the first error message.
🌐
Fly.io
community.fly.io › questions / help
Table Doesn't Exist in Database - Questions / Help - Fly.io
April 26, 2022 - I’m making an education website using remix.run and prisma, and uploaded everything without errors, but I’m getting this error:
🌐
Baserow
community.baserow.io › technical help
Discussion: how do you sync an external database with baserow? - Technical Help - Baserow
September 1, 2023 - In my use case, Baserow makes a very good front-end for databases that may not have a GUI, or may have a very primitive GUI. For a lot of CRM use cases, being able to just have a list of users along with some metrics or some tags is very valuable. But i’m finding that the syncing code is ...
🌐
Reddit
reddit.com › r/typescript › what are the biggest gotchas/weirdnesses of prisma?
r/typescript on Reddit: What are the biggest gotchas/weirdnesses of Prisma?
November 19, 2023 -

I’m writing v2 of an app I maintain and am considering moving from Sequelize to Primsa.

From my initial investigations I really like Primsa’s typescript support and the fact it returns plain JavaScript objects rather than complex model classes. However I’ve also encountered a few weirdnesses and quirks that have set my spidey-sense tingling and given me pause about adopting it.

In particular, the fact it generates custom client code to your node_modules seems very unusual (at least I’ve never seen this before) and ripe for causing unexpected, hard to debug problems - e.g. when caching dependencies on a build server.

It also seems strangely hard to have a createdBy column on database tables without an incredible amount of boilerplate setting up inverse relationships on your User model for every single other model in your schema.

And (I think a common complaint) not being able to split up your schema file is quite annoying.

I’ve only been toying with it for a couple of days and I’ve already run into these three wrinkles, which suggests to me that if I were to carry on, I might run into more. Is that the case? Are there other rough edges I should expect to encounter? It seems to make a lot of helpful things much easier, which is great. What does it make harder?

I’m also interested in hearing about any unexpected problems you ran into using Prisma in production - things it would be hard for me to figure out/predict from first principles and are only really learned through painful experience.

Asking here rather than on a Prisma sub in the hope of getting a wide range of responses. But I may ask there as well. Thanks!

🌐
LIVEcommunity
live.paloaltonetworks.com › t5 › cortex-cloud-discussions › remove-deleted-containers-from-results › td-p › 548023
LIVEcommunity - Remove deleted containers from results - LIVEcommunity - 548023
September 19, 2023 - https://docs.paloaltonetworks.com/prisma/prisma-cloud/prisma-cloud-admin-compute/configure/rule_orde... ... Click Like if a post is helpful to you or if you just want to show your support.
🌐
Prisma
prisma.io › dataguide › sqlite › creating-and-deleting-databases-and-tables
SQLite: How to Create, Delete and Manage Databases
If it does not exist, then the statement is simply ignored and nothing happens. Because SQLite does not have a separate server process like other relational databases such as MySQL or PostgreSQL, there is not a need for a DROP DATABASE statement. SQLite is an embedded database engine, so in order to drop a database you have to delete ...