Confusing error message when delete failure because of relationship
See original GitHub issueProblem
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,
},
}),
])
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:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Doesn’t seem to be an issue if you enable referential actions