Tagged: 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.
Prisma error P2025: An operation failed because it depends on one or more records that were required but not found
P2025 fires when you `update`, `delete`, or `connect` a record by ID that doesn't exist in the database. Check existence first with `findUnique`, or catch the error and return a proper 404 instead of a raw crash.
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.
Error: @prisma/client did not initialize yet. Please run "prisma generate"
Run `npx prisma generate` to regenerate the Prisma Client after changing your schema, after a fresh `npm install`, or after pulling changes from git — the generated client isn't committed to your repo by default.
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.
Prisma error: Environment variable not found: DATABASE_URL
Prisma can't find `DATABASE_URL` in your environment at the moment it's reading `schema.prisma` — usually because `.env` isn't in the project root, isn't loaded yet, or the variable name doesn't match exactly what's referenced in your `datasource` block.
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.
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.
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.
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.
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.
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`.
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).