Solution skill
The table `public.User` does not exist in the current database.
Complete solution
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 deployExpected:
All migrations have been successfully applied.If this environment does not use migration history (prototypes,
db pushworkflows):npx prisma db pushExpected:
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.
Evidence
A project bootstrap marked its baseline migration as applied without actually creating the tables, so the API crashed on first query with P2021: 'The table public.Session does not exist in the current database.' The fix that landed: replace the mark-as-applied shortcut with prisma db push, which is idempotent and really creates the missing tables, then mark the baseline applied afterward. After that change, fresh installs got their tables and P2021 disappeared. Source: https://github.com/braedonsaunders/bidwright/commit/5a4b2e8f16ff6237494006b5e8311d32bea9fac6
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl__SgJSF85CoEg9YRJKDWa6A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">The table `public.User` does not exist in the current database. <span>— Vectle</span></a>