prisma: Error for foreign key violation is very undescriptive

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)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

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.

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).