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
Null constraint violation with referential actions #8264
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I don't think Prisma is doing anything here. Referential actions live on a database level and are only configured in Prisma Schema. When you migrate your database, the generated SQL is executed and when you run a query later, that SQL just becomes active and does what it is configured to do. In your example: This is the logging you get when you have it all enabled (https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/logging + https://www.prisma.io/docs/concepts/components/prisma-client/debugging/):
As you can see it basically tries to run a |
Here is the SQL of the database for context:
|
Yes I agree Prisma is not doing anything which isn't expected base on what I can set in the prisma schema. In other words, I would like the prisma schema to allow me being specific about the intent of the referential actions. |
I think this would be a feature that we will need to add to the schema in order to enable this. cc @tomhoule Workaround would be manually modify the migration which migrate allows. |
Ah yes, that's something that isn't supported at the database level though. We should ensure this is documented properly, and advise to use a trigger-like workaround for now. EDIT: Docs already mention the limitation here: https://www.prisma.io/docs/concepts/components/prisma-schema/relations/referential-actions#setnull |
Bug description
After upgrading to 2.27.0 I also started using the referential actions. In my e2e tests i delete all entities based on a tenantId (multi-tenant setup)
Now when using
prisma.locations.deleteMany({where: {tenantId: "myTenantName"}})
I get:I checked the new migration file and the "Location" models foreign keys have not been touched (no change to the initial migration which is as expected).
The reason is with the
SetNull
prisma decides to set both ids to null which does not work for the model "Data" becausetenantId
is itself part of the composite primary key.How to reproduce
Use provided model and this script:
Expected behavior
Should set only the optional Id to null and ignore the tenantId since it's part of the composite primary key.
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: