Prisma Error P2021: Table Does Not Exist

Prisma error P2021 (Table Does Not Exist) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

Error code P2021 Prisma Last verified 2026-08-19

Quick Answer

Run npx prisma migrate dev (development) or prisma migrate deploy (production) to apply pending migrations. If that does not apply, for prototype stages without migration history, run npx prisma db push to sync the schema — the full checklist is below.

Error Code

Error code: P2021
Official name: Table Does Not Exist
Service: Prisma

What does this error mean?

The table {table} does not exist in the current database.

Common Causes

How to Fix

  1. Run npx prisma migrate dev (development) or prisma migrate deploy (production) to apply pending migrations
  2. For prototype stages without migration history, run npx prisma db push to sync the schema
  3. Verify DATABASE_URL points to the intended database (and correct schema for PostgreSQL)
  4. Confirm the model name in the schema matches the failing table - Prisma pluralizes by default
  5. Check migration status with npx prisma migrate status to find failed or missing migrations

Code Examples

Apply pending migrations bash
npx prisma migrate dev
# or for production:
# npx prisma migrate deploy

migrate dev is for local development; migrate deploy applies existing migrations on production.

Sync schema without migration history bash
npx prisma db push
# pushes the schema directly; fine for early prototyping

db push creates the tables straight from the schema - no migration files are recorded.

Framework-Specific Fixes

prisma-cli

npx prisma migrate dev applies pending migrations and regenerates the client in one step.

npx prisma migrate dev
# applies pending migrations, regenerates Prisma Client
nestjs

Run migrations as part of the deploy pipeline (npm run prisma:migrate) before the app starts serving.

// package.json
"prisma:migrate": "prisma migrate deploy",
"start": "prisma migrate deploy && node dist/main.js"

You Might Also Like

Frequently Asked Questions

Why am I seeing Prisma error P2021?

Most often this happens when migrations were never applied (fresh clone, skipped prisma migrate dev), or when schema changes exist locally but were not pushed with prisma db push or migrate dev.

How do I fix Prisma error P2021?

Run npx prisma migrate dev (development) or prisma migrate deploy (production) to apply pending migrations.

Which frameworks have documented fixes for error P2021?

This page documents fixes for: prisma-cli, nestjs.

Official Sources

This page is based on the official Prisma documentation linked below and adds practical troubleshooting guidance on top.