Solution skill
P3005: The database schema is not empty.
Complete solution
Fixes Prisma error P3005 'The database schema is not empty' during migrate deploy by baselining the existing database: mark the initial migration as already applied with migrate resolve --applied instead of letting migrate try to create tables that exist. Use when deploying to a database that was created outside Prisma migrations. Not for drift errors or failed migrations.
TL;DR: Your database already has tables but Prisma has no record of creating them. Tell Prisma the current schema matches your first migration with prisma migrate resolve --applied "[first-migration-name]", then deploy normally. Do not drop the database to fix this.
Error: P3005: The database schema is not empty.Steps
Confirm the situation: tables exist, migration history does not:
npx prisma migrate statusExpected: it reports P3005 or shows every migration as pending against a non-empty database.
Verify your first migration actually describes the existing schema. Diff it:
npx prisma migrate diff --from-migrations ./prisma/migrations --to-schema-datamodel prisma/schema.prisma --shadow-database-url "$SHADOW_DATABASE_URL"Expected: an empty diff. If the diff is not empty, fix the schema first; baselining a mismatch just moves the pain.
Baseline the database:
npx prisma migrate resolve --applied "20240101000000_init"Use the real name of your first migration folder. Expected:
Migration 20240101000000_init marked as applied.Deploy:
npx prisma migrate deployExpected:
No pending migrations to applyor only genuinely new migrations apply.
When to use
- The exact code is P3005 on
migrate deployagainst a database built bydb push, a dump restore, or another tool - Adopting Prisma Migrate on a brownfield database
When not to use
- The database is disposable (local dev):
prisma migrate resetis faster and honest - You have real migration history and a migration failed halfway: that is P3018, not P3005
Compatibility
Prisma Migrate 3.x through 6.x. PostgreSQL, MySQL, SQL Server.
Variant phrasing: P3005 right after prisma db push in staging
db push creates tables without writing migration history. Baseline once, then use migrate deploy from then on.
Variant phrasing: P3005 on a restored production dump
The dump has tables but no _prisma_migrations rows. Baseline against the migration that matches the dumped schema.
Why it happens
migrate deploy refuses to run its CREATE TABLE statements against a non-empty database because that would destroy or duplicate existing tables. The --applied baseline writes a history row claiming the first migration already ran, so Prisma treats the existing schema as its starting point.
Edge cases
- Baseling the wrong migration name silently lies to Prisma; later migrations may fail in confusing ways. Verify with the diff in step 2.
- If the existing schema only partly matches, consider
db pullinto a fresh schema first to capture reality. - Some teams baseline every environment once and document the command in their deploy runbook so nobody re-runs it.
Evidence
A staging deployment failed with P3005 because the staging database already had tables created by an earlier db push, while the migration history was empty. The recovery that worked: run prisma migrate resolve --applied against the initial migration to tell Prisma the existing schema matches it, then run migrate deploy normally. After baselining, deploys applied only new migrations and P3005 never returned. Source: https://github.com/tanjiljishad/store-spy/blob/HEAD/docs/staging-deployment.md
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_vYl4EiZTltdySVpd9UICiA" 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">P3005: The database schema is not empty. <span>— Vectle</span></a>