Prisma is automatically converting @db.Text to JSON?

Prisma is automatically converting @db.Text to JSON? What if it's not JSON? currently it's throwing an image and in the schema we have defined that field as @db.Text but for some reason Prisma is still trying to convert to JSON?
3 Replies
Prisma AI Help
Prisma AI Help2mo ago
You opted for speed from this bot. Let's conjure up an answer right now! No, Prisma does not automatically convert fields defined as @db.Text to JSON. In the Prisma schema, if you define a field as String @db.Text (or similar), Prisma will treat it as a plain text field, not as JSON. Prisma only treats fields with the Json type (or @db.Json) as JSON and will parse/serialize them accordingly. If you are seeing Prisma try to parse a @db.Text field as JSON, this is unexpected behavior and not how Prisma is designed to work. The @db.Text type should store and retrieve raw text, regardless of its content (image URLs, plain text, etc.), and Prisma should not attempt to parse it as JSON. This is supported by the official documentation, which shows that @db.Text maps to a text column in the database and is handled as a string in Prisma Client, not as JSON data Prisma schema reference: model field scalar types. If Prisma is attempting to parse a @db.Text field as JSON, it could be due to a misconfiguration or a bug. Double-check your schema to ensure the field is not typed as Json. If the issue persists, consider opening a bug report with a minimal reproduction. In summary: @db.Text fields should not be parsed as JSON by Prisma. Only fields explicitly typed as Json or @db.Json are treated as JSON Prisma schema reference: Json. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
DeathlyNocturnal
DeathlyNocturnalOP2mo ago
Hmm okay, sounds like I need an adult, as we are seeing a field set to @db.Text and is also in the DB set as Text is trying to be parsed as JSON from the Prisma client. So unsure what is happening there? Is there something I can do?
Nurul
Nurul2mo ago
Do you have a reproduction for this issue? I don't understand what exactly is causing this behaviour

Did you find this page helpful?