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
Cascade deletes doesn't work on many to many relations #2328
Comments
I can confirm this bug is present in the latest alpha |
Pretty nasty bug; also occurs in the explicit M2M example on the docs |
This issue should be renamed to: Support cascade delete in Many-to-Many relationships and be tagged with topic:cascade. |
Any update on this? This is a very high priority bug which can make or break almost any project. |
Now I can only look at database relationships and delete them using $queryraw. |
This issue seems to also affect Querying my data to show initial stateQuery where query getDoc ($id: String) {
document(where: {id:$id}){
documentKind{
id
KindId
DocumentId
}
}
} Result: {
"data": {
"document": {
"documentKind": [
{
"id": "cuid1",
"KindId": "kind1",
"DocumentId": "doc1"
},
{
"id": "cuid2",
"KindId": "kind2",
"DocumentId": "doc1"
}
]
}
}
} Now I want to disconnect the Mutationmutation updateDoc($id:String, $data:DocumentUpdateInput!) {
updateOneDocument(where:{id:$id},data:$data){
documentKind {
KindId
DocumentId
}
}
} Attempt 1 with "disconnect"Variables: {
"id": "doc1",
"data": {
"documentKind": {
"disconnect": {
"KindOnDocument_AB_unique": {
"KindId": "kind2",
"DocumentId": "doc1"
}
}
}
}
} Result: {
"error": {
"errors": [
{
"message": "Invalid `prisma.document.update()` invocation in /node_modules/nexus-plugin-prisma/dist/schema/builder.js:202:93
198 locallyComputedInputs: publisherConfig.locallyComputedInputs,
199 });
200 }
201 args = this.paginationStrategy.resolve(args);
→ 202 return photon[mappedField.photonAccessor][mappedField.operation](args)
The change you are trying to make would violate the required relation 'DocumentToKindOnDocument' between the `Document` and `KindOnDocument` models.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"updateOneDocument"
]
}
],
"data": {
"updateOneDocument": null
}
}
} Attempt 2 with "set"Variables: {
"id": "doc1",
"data": {
"documentKind": {
"set": [{
"KindOnDocument_AB_unique": {
"KindId": "kind1",
"DocumentId": "doc1"
}
}]
}
}
} Result: Same as above. Note that I'm using |
I am also having this issue. More than 5 months since this has been opened an there is still no fix? What's the deal? |
Could this be related to #2057? |
I'm still getting this error until this day using when foreign key constraint is set with on DELETE CASCADE with one to one relationship on a PostgreSQL table using Version 12 |
If you want to delete nested records in cascade deleting the parent, before you need set constraint key as nullable in the database or in your schema. This solve the issue. |
This is actually a bug as it should not be needed for cascade, see #4650 |
I'm also facing this issue. When deleting directly in the db (or by using tools like pgAdmin), N:M relation is correctly deleted, the prisma client prevents performing this delete operation. |
What is the status with this? What is the solution? Has been almost a year since this was opened |
so what is the solution when you face this? this is not a minor bug! what can i do to go forward with my project? if i reinitalize prisma from the start, will i face this issue again? |
You will have this error again until it is fixed. Straight to the point, I have an API endpoint which will call to prisma.ENTITY.deleteMany. If I do just that, the bug we are talking about will be thrown. To "fix" this, I added a call to prisma.executeRaw and deleting the things I want deleted in the database "manually" Documentation here |
@JunquerGJ Thanks, i think this is what i'm going to do for now, otherwise the project i'm working on is frozen because of this bug. I hope they prioritize this issue. |
Cascade delete currently doesn't work for me for 1:n relations either. |
Can confirm that I'm having the same issue with a 1:n relationship (latest prisma: 2.20.1) |
This issue is opened by almost one year. How is it possible that with all the huge work that the prisma team is doing to improve the library, no solution has been provided yet? This is quite a big issue, and I think that it should also be labeled as bug. |
@euberdeveloper maybe, this is just a small issue seen relatively and not prioritized so highly |
@philippfo9 Yes, I guess, but it does not seem a tricky fix, it is the default behaviour of SQL cascade to delete the related tuples (I guess the problem is because of prisma checks). |
It's time for one of us to send a PR 😁 🤙 |
This is an annoying bug ! I am somehow disappointed + been so long since it is open |
I'm having this issue too, it's very annoying because this is natively supported by PostgreSQL and it's one of the advantage of using a relational database. More over this behavior is completely valid and a raw query works as expected, so the prisma client is preventing a legit behavior. Can we open a PR on our own ? Is it a tricky change, can we have some guidelines to work on it ? |
We are actively working on this. This week the schema working group made their decision on how it should look like in the data model. The next and final step is the implementation. |
Is there any way we can get around here until the new fix is released? If the official can give a best practice I think it will definitely help a lot. (a solution for everyone until the problem is fixed) |
Our project heavily depends on cascade deletions. After weeks of work to migrate from Typeorm to Prisma, we faced with this issue. This is big, Prisma should've mention this shortcoming in limitations so we would wait until it fixed. This not some behavior you would expect from a "production-ready" software! |
Fixed in prisma/prisma-engines#1947 Instructions on how to use this, and a place to give feedback: #7816 |
This has now been released as a preview feature flag. You can read about it in the release notes for 2.26.0: https://github.com/prisma/prisma/releases/tag/2.26.0 If you have any feedback, please use this issue: #7816 |
It still does not work with implicit many-many relations |
Then please open a new issue and provide a full reproduction. Thanks. |
Bug description
I'm getting an error when I try to remove an entity from a explicit many-to-many relationship.
The change you are trying to make would violate the required relation 'ContactToServerToServer' between the
ContactToServerand
Servermodels.
How to reproduce
I am using an empty posgresql database and Typescript so:
Expected behavior
I wanted to delete the server, ( and doing so, delete also the entry in the relation table )
The created contact should not be affected
Prisma information
My prisma schema:
and my Prisma queries:
Environment & setup
Stack Trace
The text was updated successfully, but these errors were encountered: