prisma: relationMode = `prisma`: Error validating: A self-relation must have `onDelete` and `onUpdate` referential actions set to `NoAction`
Bug description
With mysql and relationMode set to prisma, I’m getting this lint error:
Error validating: A self-relation must have `onDelete` and `onUpdate` referential actions set to `NoAction` in one of the @relation attributes. (Implicit default `onDelete`: `SetNull`, and `onUpdate`: `Cascade`) Read more at https://pris.ly/d/cyclic-referential-actions
Even though that should only be the case if it uses MongoDB or SQL Server providers as explained here?
Prisma information
# provider = "mysql"
# relationMode = "prisma"
model DashboardFolder {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
name String
parentFolderId String?
workspaceId String
parentFolder DashboardFolder? @relation("ParentChild", fields: [parentFolderId], references: [id])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
childrenFolder DashboardFolder[] @relation("ParentChild")
typebots Typebot[]
}
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 19 (5 by maintainers)
Not sure if this has something to do with this issue, but I’m getting an issue when trying to delete a self-relation. When I try deleting all nested children in a 1-M self-relation, I get the error below. However, using a raw query works.
Schema:
Prisma delete query (trying to delete all subtopics):
Error message:
Solution (raw query):
Is there any current solution to this without using a raw query?
@jkomyno did some sleuthing, and I am here with the simple job to report his findings:
This is currently working as designed, although we are lacking the documentation for it.
https://github.com/prisma/prisma/issues/9931 was an issue triggered by a user having a self relation, and it then crashing Prisma Client. This was fixed by expanding our SQL Server and MongoDB cyclic ref actions detections to these cases as well in this PR: https://github.com/prisma/prisma-engines/pull/2415
Here is the explanation why this is needed:
And the “workaround”:
Would this work for you @baptisteArno?
Yes, totally fine! Thank you for the investigation 👌
Hello, I have almost the same problem. Have you managed to solve it somehow?
I tried the NoAction for onDelete and for onUpdate but I’m still getting this error. (Provider MongoDB)
My Model
I would love if someone could help me out.
Hi @jkomyno , I explained here.
Restrictthrows error in my case cuz it asks me to handle related rows (I don’t quite remember the error; i think it’s error 2014 “The change you are trying to make would violate the required relation ‘ChildToParent’ between theChildandParentmodels.”). I need aNothingrelationMode to handle the onUpdate and onDelete checking myself.