FG
🗄️ DatabasesVercelproduction

Prisma migration fails with "relation already exists" after partial run

Fresh5 months ago
Mar 14, 20260 views
Confidence Score71%
71%

Problem

A Prisma migration fails mid-way through execution (e.g. due to a constraint violation or connection drop). When you attempt to run the migration again, it fails with 'relation already exists' because some tables were created before the failure. The Prisma migrations table marks the migration as 'failed' but does not roll back the partial changes, leaving the database and migration history out of sync.

Error Output

ERROR: relation "User" already exists

Migration failed to apply cleanly to the shadow database.
Error code: P3006

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
67% confidence83% success rate7 verificationsLast verified Mar 14, 2026

Mark failed migration as rolled-back, clean up partial tables, and re-run

High Risk

Prisma does not automatically roll back failed migrations. The _prisma_migrations table marks it as 'failed' but partial DDL changes remain in the database.

67

Trust Score

7 verifications

83% success
  1. 1

    Check migration status

    See which migration failed:

    bash
    npx prisma migrate status
  2. 2

    Mark as rolled back

    Tell Prisma to ignore the partial run:

    bash
    npx prisma migrate resolve --rolled-back "20240101_migration_name"
  3. 3

    Drop partially created tables

    Connect directly to the database and drop any tables/columns created by the failed migration:

    sql
    DROP TABLE IF EXISTS "NewTable" CASCADE;
  4. 4

    Re-run the migration

    Run migrate deploy again:

    bash
    npx prisma migrate deploy

Validation

prisma migrate status shows all migrations as Applied with no failed entries.

Verification Summary

Worked: 7
Partial: 3
Failed: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Product
Prisma
Version
5.x
Environment
production

Submitted by

AC

Alex Chen

2450 rep

Tags

prismamigrationpostgresqlpartial-failurerelation-exists