prisma: Throw a better error message when a Postgres column exceeds its size limit

Bug description

Postgres column says <unknown> for column type in update()

StudyGuide is a pretty deeply nested entity that I’m creating at once (this is in a bulk create script that parses a CSV of base data), so it goes like StudyGuide -> Topic -> Section -> Concept -> Card -> Content, and each of these has fields that are quite long.

Using DEBUG='*' lets me see the exact mutation that caused the issue (it’s 4000 lines long) so still it’s a bit of a hassle to re-parse the mutation and figure out exactly which ones are candidates for exceeding some length.

So this bug is not about the underlying cause, which I’m assuming is that I’m trying to insert text that’s too long into a char/varchar. The bug is that the error message is unclear for me to figure out which column it is:

Invalid `prisma.studyGuide.update()` invocation:


  The provided value for the column is too long for the column's type. Column: <unknown>
    at PrismaClientFetcher.request (/Users/louis/branches/srs/server/node_modules/@prisma/client/src/runtime/getPrismaClient.ts:762:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at main (/Users/louis/branches/srs/server/prisma.bak/spreadsheetseed.ts:104:5) {
  code: 'P2000',
  meta: { column_name: '<unknown>' }
}

How to reproduce

Expected behavior

It tells me the problematic column, or at least any other useful metainformation

Prisma information

2.0

Environment & setup

Mac Prisma 2 Node 14.4

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 17 (11 by maintainers)

Most upvoted comments

Ok, I figured mine out. It was indeed being caused by old Prisma1 cuid fields in varchar(25) rather than varchar(30), but they were in a many-to-many join table. Apparently, prisma-upgrade does not generate the SQL statements to take care of such fields. I altered the table manually, and everything seems to be working.

MySQL returns the column with the error, so we display it there.

SQLite does not have the notion of a limited length string columns if I remember correctly, so this error can’t occur.

This error comes directly from the database. We probably cannot do better.

That should not be the case for new Prisma projects, only if you upgrade from Prisma 1 possibly. You can follow prisma/upgrade#43 for our approach of fixing this @bardak-dev - it should be available soon in our P1-P2 upgrade tool.

That was the case, thank you 👍

That should not be the case for new Prisma projects, only if you upgrade from Prisma 1 possibly. You can follow https://github.com/prisma/upgrade/issues/43 for our approach of fixing this @bardak-dev - it should be available soon in our P1-P2 upgrade tool.

  • The debug error message says <unknown>, which makes it very, very difficult for a user to usefully debug this issue.

That is a bug that should have an issue and then should just be fixed (cc @pantharshit00)

2. The prisma-upgrade tool defaults to using VARCHAR(25) (or it takes it from prisma1) and then uses assigns it to use cuid, which causes this problem (I want to emphasize that I did nothing manually in this process in terms of altering the tables yet, besides running prisma-upgrade)

Varchar(25) is indeed the value in the Prisma 1 type database. I will point this out to the people working on the upgrade tool, so they can investigate.