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.

Error for foreign key violation is very undescriptive

See original GitHub issue

Descriotion

I have an old database. There are foreign key violations. Since basically all tables are interconnected, I cannot load any table from the studio. I would like to use a studio or some other tool to fix the database.

Problem

Error in Prisma Client request: 

Error: Failed to validate the query `Error occurred during query validation & transformation:
Query (object)
  ↳ findManyadresy (field)
    ↳ take (argument)
      ↳ Argument does not exist on enclosing type.` at `.Query.findManyadresy.take`
    at PrismaClientFetcher.request (C:\Users\akxe\AppData\Roaming\Prisma\Studio\-Users-akxe-Documents-Programming-rita\runtime\index.js:1:228283)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async C:\Users\akxe\Documents\Programming\rita\node_modules\@prisma\cli\build\index.js:2:1616391
    at async Photon.request (C:\Users\akxe\Documents\Programming\rita\node_modules\@prisma\cli\build\index.js:2:1616874)
    at async PhotonService.respond (C:\Users\akxe\Documents\Programming\rita\node_modules\@prisma\cli\build\index.js:2:868721)
    at async WebSocket.StudioServer.onWSMessage (C:\Users\akxe\Documents\Programming\rita\node_modules\@prisma\cli\build\index.js:2:774591)

This error is not very much helpful. It does not provide anything to go reason about.

Suggested solution

How about an error:

Error in Prisma Client request:

Error: Failed to validate the query `Row for column "fieldName" of table "tableName" was not present for value(s): 1,2,3,4,5,6... and X more.`

Alternatives

You pick one, there will be many

Additional context

Prisma 2.6.0, applies to 2.7.0, the same (waiting for nexus-plugin-prisma to upgrade)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
Akxecommented, Sep 21, 2020

Hm, that is a very different error message than the one you were getting in Prisma Studio - correct?

Indeed, the error from studio is very generic…

Can you possibly put this into a new app and upload it to Github so we can reproduce it?

I can, but I am now at vacation and will return on a week. You should have all necessary in here. I’ll do it in a week if it is still needed.

1reaction
Akxecommented, Sep 18, 2020

Thanks! And your theory for an explanation is that Adresy contains an invalid foreign key in idFirmy that is backing the relation in that table, correct?

Well… I know for sure, that none of “Adresy” is invalid in “Firmy”, but I am almost 100% confident, the others do have invalid foreign keys.

EDIT: The SQL SELECT * FROM firmy WHERE NOT EXISTS (SELECT idFirmy FROM adresy); produces 0 rows.

I have also tested relations:

  • firmy_adresy_idFirmyTofirmy
  • firmy_adresyTofirmy_idFirAdr
  • firmy_adresyTofirmy_idKorespAdr
  • firmy_adresyTofirmy_idLepicAdr
SELECT * FROM adresy WHERE not exists (SELECT idAdr FROM firmy);
SELECT * FROM adresy WHERE not exists (SELECT idKorespAdr FROM firmy);
SELECT * FROM adresy WHERE not exists (SELECT idLepicAdr FROM firmy);

None of them produces any row(s).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error 546 - Sybase Infocenter
Foreign key constraint violation occurred, dbname = '%. ... For example, error 546 can be raised when Adaptive Server detects that the data...
Read more >
Get error foreign key violation - Stack Overflow
I have tried to find solutions here and have implemented like delete parent tables (user, in my case), and create that table again...
Read more >
Foreign key violation when trying to insert into a table [closed]
I am trying to insert value 15 to ID of A but a FK violation occurs. error is similar to given below: ERROR...
Read more >
Foreign key violation error when starting flow with de ... - GitHub
Description When trying to submit a flow run without registered agent (i removed agent via ui) (but agent was still running though), prefect...
Read more >
3 common foreign key mistakes (and how to avoid them)
Foreign key constraints are important to any SQL database, but they can also cause problems if they're not implemented correctly.
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