Tagged: postgresql

Prisma

Prisma error P2002: Unique constraint failed on the fields

P2002 means you're trying to insert or update a record with a value that already exists in a column marked `@unique`. Catch it explicitly with a try/catch and check `error.code === 'P2002'`, or query first to give the user a clear message instead of a raw 500.

Draft·
Prisma

PrismaClientInitializationError: Can't reach database server

This means Prisma can't establish a connection to your database at all — usually a wrong `DATABASE_URL`, a paused/suspended Neon project, a missing `?sslmode=require`, or a firewall blocking the connection.

Draft·
PostgreSQL

PostgreSQL error: password authentication failed for user

The username/password in your connection string doesn't match what the database expects. Regenerate or re-copy the full connection string from your provider's dashboard (Neon, Supabase, etc.) rather than typing it by hand.

Draft·
PostgreSQL

PostgreSQL error: relation "table_name" does not exist

Your database doesn't have this table yet — either your migrations haven't run against this database, or you're pointing at the wrong database/schema entirely. Run `npx prisma migrate deploy` (or `migrate dev` locally) to sync the schema.

Draft·
PostgreSQL

PostgreSQL error: too many connections for role

You've hit your database's connection limit — extremely common in serverless environments (Vercel functions, Lambda) where each invocation can open a new connection. Use a connection pooler (Neon's pooled connection string, or PgBouncer) instead of connecting directly.

Draft·
Prisma

Prisma error: Drift detected — your database schema is not in sync with your migration history

Someone (or something) changed the database schema directly — outside of Prisma's migration files — so the actual database no longer matches what Prisma's migration history says it should look like. You need to either reconcile the drift manually or reset the dev database if the data is disposable.

Draft·
PostgreSQL

PostgreSQL error: current transaction is aborted, commands ignored until end of transaction block

One query inside a transaction failed, and PostgreSQL refuses to run any further commands in that same transaction until you explicitly `ROLLBACK`. Every query after the failure will show this same error, even valid ones — you have to roll back before doing anything else.

Draft·
PostgreSQL

PostgreSQL error: syntax error at or near "user"

"user" (along with "order", "group", "table", and others) is a reserved SQL keyword in PostgreSQL. Using it unquoted as a table or column name causes a syntax error. Either quote it with double quotes everywhere, or — better — rename it to avoid the conflict entirely.

Draft·
Prisma

Prisma error P2003: Foreign key constraint failed on the field

You're trying to create or update a record that references a foreign key ID which doesn't exist in the related table — for example, creating an Article with a `pillarId` that doesn't match any real Pillar. Verify the referenced ID actually exists before the write, or handle the error to show a clear message.

Draft·
Prisma

Prisma error P2021: The table does not exist in the current database

Prisma's client was generated against a schema that includes a model whose table was never actually created in this specific database — usually because migrations haven't been applied to this environment, or you're connected to the wrong database entirely.

Draft·
PostgreSQL

PostgreSQL error: value too long for type character varying(255)

You're trying to insert a string longer than the column's defined length limit. Either validate and truncate the input before saving, or increase the column's length limit — for genuinely long text (like article content), use `TEXT` instead of a length-limited `VARCHAR`.

Draft·
PostgreSQL

PostgreSQL error: FATAL: sorry, too many clients already

This is a server-wide connection limit, distinct from the per-role "too many connections for role" error — the entire database instance has hit its max_connections ceiling from all roles combined. It's the same root fix as the per-role version: use a connection pooler in serverless environments, and make sure you're not creating a new PrismaClient per request.

Draft·
PostgreSQL

Error: connect ECONNREFUSED 127.0.0.1:5432

Your app is trying to connect to a PostgreSQL server on localhost, but nothing is listening there — either your local Postgres isn't running, or `DATABASE_URL` still points at localhost when it should point at your actual hosted database (like Neon).

Draft·