Due to some legacy DB design, we have some fields ...
# orm-help
j
Due to some legacy DB design, we have some fields that are defined as a
string
in the DB but have constraints placed on the field at the DB level to restrict the values to a set (just like an enum). In previous versions of Prisma, we defined these in our schema as an
enum
and all was well, it worked perfectly. However in trying to upgrade to Prisma 4, we've started to get the error
Copy code
meta: {
    code: 'XXUUU',
    message: 'db error: ERROR: cannot create enum of unspecified type'
  },
Which I'm assuming is that Prisma no longer knows how to cast the string db value to the enum defined in the schema. Any tips for how to progress? Any way to define a string value in prisma with a set of possible string values?
1
j
When and where are you getting that error message? What version were you using before where this used to work? Can you provide a minimal reproduction for SQL so we can play with this?
j
Thanks @janpio, ok it's actually a problem with
enums
and not the string issue I thought it was. Previous Prisma version: 3.14.0 Database connector: CockroachDB That error message is being thrown when we run a raw query where we are adding a
where
clause with an enum I have built a reproducible repo https://github.com/jared-fraser/prisma-enum I've included 2 package files to allow you to swap from 3.14 to 4, to show that it worked in 3.14 and not in 4. Problem line: https://github.com/jared-fraser/prisma-enum/blob/master/script.ts#L20
So solution is I need to cast the enum to the enum name
Copy code
AND te.source = ${SourceEnum.testA}::source_enum
then the query works again
j
Ah that makes sense. Good I asked for the source. Can you maybe create an issue with this? This is mostly intentional, but still unexpected for you so we should track this. With the info you included above we should almost have all the things we need, just add the additional details that the tempalte is asking for: https://github.com/prisma/prisma/issues/new/choose Thanks
j
Thanks Jan, have created the issue https://github.com/prisma/prisma/issues/14300
👍 1