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.

OnUpdate default referential Integrity action while using Prisma to handle referential Integrity

See original GitHub issue

Intro

it is mentioned in the docs that the default referential integrity actions are these here image

but it is also stated in the docs that while using Prisma to handle referential integrity that the available actions are image

It is not clearly mentioned in the docs that you should manually set the onUpdate to noAction


Problem

enabling the preview feature referentialIntegrity and attempting to update a record that has relation lead me to this error (creating and deleting records works fine)

Message: 
Invalid `prisma.institution.update()` invocation:


  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError { code: 1105, message: "symbol db.Institution.id not found", state: "HY000" })) })

Query: 
prisma.institution.update(
{
  where: {
    id: 44,
  },
  data: {
    firstName: "Random",
  },
  select: {
    id: true,
    firstName: true,
  },
}
)

Solution

setting onUpdate to noAction resolved this error. I would like to propose to either set the default action while using referentialIntegrity for update operation to noAction (since this is the only available option at this time) or at least mention this explicitly in the documentation


Notes

I should also note I was using Prisma combined with Planetscale, i don’t know if this is relevant but i’ll just leave it here

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
NBruhnocommented, Dec 22, 2021

Is it possible that you did not run npx prisma generate to regenerate your Prisma Client after making the change? That is necessary for the Client to learn about the change in expected referential action and thus run the correct queries (or no queries at all in this case).

Apologies, but I only ran prisma migrate dev --name <name>, (which I believe runs generate regardless of pending migrations or not). I think it might have mixed with the issue that I had previously with running prisma while using pnpm in my repo, which didn’t update the client properly unless I did a reinstall of the client when doing either migrate or generate. But it looks like that is no longer an issue either (don’t know which version fixed that for me, or if it was a pnpm issue).

I cannot reproduce my generate issue anymore. It’s just the onDelete and onUpdate that does not seem to have sane defaults for referentialIntegrity, as you have already mentioned.

0reactions
janpiocommented, Aug 10, 2022

We think this is only a docs issue - so closing and creating a new one there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Special rules for referential actions in SQL Server and MongoDB
Be aware that by default, the relationMode = "prisma" mode is used for MongoDB, which means that Prisma manages referential integrity. Given the...
Read more >
How to Enforce Referential Integrity with Prisma
Like CASCADE, we can use SET NULL on delete and update operations. The foreign key column from the child table (books) will be...
Read more >
Referential Integrity (ON DELETE, ON UPDATE) - SQL Server
A referential integrity enforces insert and update rules for the tables with the foreign key and the corresponding primary key constraint.
Read more >
Foreign keys | YugabyteDB Docs
You use a foreign key constraint to maintain the referential integrity of data ... NO ACTION (default) - when the referenced rows in...
Read more >
Why isn't referentialIntegrity = "prisma" preventing foreign keys ...
In the image you can see that the migration works. ... been created from before I addedreferentialIntegrity = "prisma" and previewFeatures ...
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