question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confusing error message when delete failure because of relationship

See original GitHub issue

Problem

Current error message:

Error: Error occurred during query execution:
InterpretationError("Error for binding \'5\'", Some(QueryGraphBuilderError(RelationViolation(RelationViolation { relation_name: "AccountToUser", model_a_name: "Account", model_b_name: "User" }))))
    at /Users/jasonkuhrt/projects/prisma/cloud/node_modules/@prisma/client/runtime/index.js:27525:19
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Code:

await prisma.$transaction([
  prisma.user.delete({
    where: {
      id: user1Data.user.id,
    },
  }),
  prisma.account.delete({
    where: {
      id: user1Data.user.accounts.create.id,
    },
  }),
])

Schema: https://github.com/prisma/cloud/blob/317e3dcd8b16c49854b5c3b53ae7bac64ec3da1c/prisma/schema.prisma#L60-L74

Suggested solution

The solution was I had to change the order of the operations, first delete accounts, then delete users.

Being told that would be nice.

Alternatives

Thinking more deeply, I just want to be able to delete the things and it “just work”. It would be nice to not think about order at all.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pantharshit00commented, Apr 16, 2021

I can reproduce. We need to make this a known error. This might also be partly related to cascade delete support because you really don’t need to do a transaction if we had that but that is separate talk.

0reactions
pantharshit00commented, Aug 1, 2021

Doesn’t seem to be an issue if you enable referential actions

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while trying to cascade-delete - Stack Overflow
The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is ......
Read more >
Error: The features could not be deleted. Failed ... - Esri Support
Cause. This error occurs if the foreign key of the relationship has a Not Null constraint. When an origin feature is deleted, the...
Read more >
Analysis of Failure to Delete a Kubernetes Cluster Namespace
Starting from the Cluster Portal. We must analyze the behavior of the API server because we delete namespaces on the cluster API server....
Read more >
Cascade Delete - EF Core | Microsoft Learn
Using anything other than cascade delete for required relationships will result in an exception when SaveChanges is called. Typically, this is ...
Read more >
Good explanation of cascade (ON DELETE/UPDATE) behavior
My first guess would be the Child records get deleted when Parent records are deleted, since Child records depend on Parent records, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found