The table `public.User` does not exist in the current database.
Fixes Prisma error P2021 'The table does not exist in the current database' by applying the missing migrations or pushing the schema so the table actually gets created. Use when queries fail with P2021 after a deploy or a schema change. Not for drift errors or failed migrations.
TL;DR: The table was never created in this database. Run prisma migrate deploy (or prisma db push if you do not use migration history here) against the database your app actually connects to, and the table appears. P2021 means the schema and the database disagree, and the database is the one behind.
The table `public.User` does not exist in the current database.Steps
- Check what Prisma thinks is pending:
npx prisma migrate statusExpected: it lists unapplied migrations, or reports the database is in sync (which means you are pointed at the wrong database).
- Apply the migrations to the right database:
npx prisma migrate deploy Expected: All migrations have been successfully applied.
- If this environment does not use migration history (prototypes,
db pushworkflows):
npx prisma db push Expected: Your database is now in sync with your Prisma schema. Missing tables are created.
- Re-run the failing query.
Expected: P2021 gone; the query returns rows.
When to use
- The exact code is P2021 naming a table your schema defines
- After a deploy, a new environment, or adding a model without generating a migration
When not to use
- The table exists but the query still fails: check the schema name (
public.vs your schema) and the connection string migrate statussays everything is applied: you are connected to the wrong database; fix DATABASE_URL
Compatibility
Prisma Client and Migrate 2.x through 6.x. All providers.
Variant phrasing: P2021 right after adding a model to schema.prisma
You added the model but never ran migrate dev --name. Generate and apply the migration.
Variant phrasing: P2021 only in production, fine locally
The production deploy skipped migrate deploy (the Dockerfile ran only prisma generate). Add migrate deploy to the container entrypoint or release command.
Why it happens
prisma generate creates client code but touches no database. Tables only appear when a migration runs (migrate deploy, migrate dev) or the schema is pushed (db push). Any pipeline that generates without migrating ships code that references tables that do not exist.
Edge cases
- Marking a migration applied without running it (a bad baseline) produces exactly this: history says done, tables say otherwise. Use
db pushto reconcile, as the source commit did. - Multi-schema Postgres: the table may exist in another schema; check
@@schemamappings. db pushwith--accept-data-losscan drop columns; prefermigrate deploywherever history exists.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.