question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Referential actions not (all) working when `referentialIntegrity` set to `prisma`

See original GitHub issue

Bug 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 of Restrict (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

  1. Create the DB with Prisma Migrate using the provided Prisma schema (cf below)
  2. Create a user with related posts
  3. 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:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
pimeyscommented, Dec 2, 2021

I will do a git bisect tonight to see why we had the regression and when exactly it was fixed.

0reactions
guillaumervlscommented, Dec 2, 2021

Looks like these problems are all gone in 3.6.0 indeed ! But I would double check if I were you, I checked quickly 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found