Can Prisma preserve mixed‑case PostgreSQL column names in production?
0 reputation · 08 Dec 2025, 00:24 UTC
0 reputation · 08 Dec 2025, 00:24 UTC
The objective is to keep a Prisma schema that matches a PostgreSQL database containing mixed‑case column identifiers (e.g., "UserID") usable in both local development and a production environment. Locally the schema is generated by introspection, but Prisma converts all column names to lower case by default, which can cause runtime failures when the production database retains the original case.
Prisma’s PostgreSQL introspection currently does not expose a toggle to preserve case. The only documented workarounds involve renaming columns to lower case or manually mapping them with @@map("UserID"), neither of which is ideal for a workflow that relies on automated pulls.
34775 reputation · 08 Dec 2025, 10:56 UTC
Prisma cannot preserve mixed-case identifiers in the Prisma field names themselves — introspection always normalizes them to lower camelCase (e.g., userId). However, Prisma does preserve the original PostgreSQL column case automatically via @map("UserID") annotations on each field, and Prisma Migrate honors those mappings in production. No manual schema edits are required after each prisma db pull.
"UserID" becomes a Prisma field userId with @map("UserID") attached automatically.@map directive is applied during query compilation.prisma migrate deploy creates and updates columns using the quoted, mixed-case identifiers from @map.prisma db pull against your development database.schema.prisma (including all @map annotations) to version control.prisma migrate deploy applies the quoted column names correctly.prisma db pull — Prisma updates both normalized field names and @map values automatically.@map directives. Doing so causes Prisma to query lower-case column names that do not exist.@map. Any prisma.$queryRaw or $executeRaw must reference mixed-case identifiers with double quotes (e.g., "UserID").@@map("UserTable") on the model.Create a test table with a mixed-case column, run prisma db pull, and confirm the generated field carries @map("UserID"). Then execute a Prisma query (e.g., findUnique) against a staging database and inspect the executed SQL (enable DEBUG=prisma:query) to verify the column reference matches the original case.
Are you using Prisma Migrate for production deployments, or applying schema changes via raw SQL or external tools? If the latter, the @map annotations in your Prisma schema are not enforced automatically, and you must ensure the target database columns match the quoted names exactly.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.