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

Prisma·Sep 12, 2026·intermediate·
Quick answer

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.

What causes this error

Unlike a raw SQL "relation does not exist" error, P2021 comes specifically from Prisma Client itself — it already knows about the model from your schema, but the database it's actually connected to at runtime never had the corresponding table created via migration.

The Fix

# Confirm which database you're actually connected to
echo $DATABASE_URL

# Apply pending migrations to that specific database
npx prisma migrate deploy

This is especially common right after creating a new Neon branch or a fresh staging database — the schema file has the model, but nothing has run migrations against that particular database yet.

Common causes / variations

  • Spinning up a new database branch (e.g. a Neon preview branch) without running migrations against it
  • DATABASE_URL pointing at a different database than you think, especially across local/staging/production .env files
  • Deploying application code before the migration step in your CI/CD pipeline actually runs

Related errors

See also: relation does not exist, drift detected.

Was this fix helpful?

Comments

Loading comments...