Referential actions not (all) working when `referentialIntegrity` set to `prisma`
See original GitHub issueBug description
Hi & thanks for the awesome work in Prisma,
Looks like when setting referentialIntegrity
to prisma
, referential actions have some problems:
- they stopped working altogether in Prisma v3.5.0
In v3.4.2:
- they default to
NoAction
instead ofRestrict
(as it is supposed to as I understand the docs) - they don’t work with composite id/unique constraints
SetNull
doesn’t work as noticed in #9483
Cheers!
How to reproduce
- Create the DB with Prisma Migrate using the provided Prisma schema (cf below)
- Create a user with related posts
- Delete the user and check the foreign key on the posts that were related to the deleted user
Expected behavior
No response
Prisma information
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
referentialIntegrity = "prisma"
}
model User {
id Int @id @default(autoincrement())
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
author User @relation(fields: [authorId], references: [id], onDelete: Cascade) # <- edit accordingly
authorId Int
}
Environment & setup
- OS: Mac OS
- Database: Planetscale
- Node.js version: v16.13.0
Prisma Version
Latest roughly working version is 3.4.2 as below (3.5.0 ignores completely referential actions)
prisma : 3.4.2
@prisma/client : 3.4.2
Current platform : darwin
Query Engine (Node-API) : libquery-engine 57771c0558568c7d08bd34c7248af5244ae16bd9 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 57771c0558568c7d08bd34c7248af5244ae16bd9 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 57771c0558568c7d08bd34c7248af5244ae16bd9 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 57771c0558568c7d08bd34c7248af5244ae16bd9 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 57771c0558568c7d08bd34c7248af5244ae16bd9
Studio : 0.438.0
Preview Features : referentialIntegrity
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Special rules for referential actions in SQL Server and MongoDB
With MongoDB, using referential actions in Prisma requires that for any data model with self-referential relations or cycles between three models, you must...
Read more >OnUpdate default referential Integrity action while using ...
Updating the schema with onUpdate: NoAction did not fix the issue initially because Prisma did not detect any schema changes when added, so...
Read more >How to Enforce Referential Integrity with Prisma
The foreign key column from the child table (books) will be set to NULL when the parent record gets updated or deleted. RESTRICT...
Read more >How Prisma Introspects a Schema from a MongoDB Database
I work as the Engineering Manager of Prisma's Schema team. ... having foreign keys, and concepts like referential integrity.
Read more >Preserve referential integrity in Database Model diagrams
Set actions for referential integrity · Double-click the relationship for which you want to set a referential action. · In the Database Properties...
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 will do a
git bisect
tonight to see why we had the regression and when exactly it was fixed.Looks like these problems are all gone in 3.6.0 indeed ! But I would double check if I were you, I checked quickly 😄