Skip to content
Latchkey

Prisma "P3005: The database schema is not empty" (baseline) in CI

P3005 means the target database already has tables but the _prisma_migrations history is empty. Prisma will not guess which migrations were already applied, so you must baseline the existing schema.

What this error means

Against a pre-existing database, migrate deploy fails with "P3005 The database schema is not empty. Read more about how to baseline...".

Prisma
Error: P3005 The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline

Common causes

An existing schema with no migration history

The database was created outside Prisma (or seeded directly), so tables exist but no baseline migration is recorded.

A CI database restored from a snapshot

Restoring a schema dump populates tables without the _prisma_migrations records, tripping P3005.

How to fix it

Baseline the existing schema

  1. Create an initial migration from the current schema (diff to an empty database).
  2. Mark it already applied with migrate resolve --applied.
  3. Then run migrate deploy for subsequent migrations.
Terminal
npx prisma migrate resolve --applied 0_init
npx prisma migrate deploy

Start CI from an empty database

If the CI database can be empty, migrate deploy applies all migrations cleanly with no baseline needed.

Terminal
npx prisma migrate reset --force
npx prisma migrate deploy

How to prevent it

  • Baseline any database that predates Prisma migrations.
  • Prefer an empty ephemeral database per CI run.
  • Do not restore raw schema dumps without recording migration history.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →