This error occurs when Prisma's shadow database (used for detecting schema drift) cannot apply your migrations cleanly. Common causes include schema drift, permission issues, manual database changes, or conflicting migrations. Resolve it by resetting your database, syncing your schema, or fixing permissions.
The P3006 error occurs when Prisma Migrate cannot apply your migration to the shadow database during development. The shadow database is a temporary, automatically-created database that Prisma uses to detect schema drift and ensure migrations are safe before applying them to your actual development database. When a migration fails to apply cleanly to this shadow database, it indicates a mismatch between your migration files, your Prisma schema, and your actual database state. This could mean your schema is out of sync with your migration history, permissions are insufficient, or the database was modified manually outside of Prisma Migrate.
Run the migration command with verbose output to see exactly what failed:
npx prisma migrate devRead the full error message—it will tell you which table, column, or constraint is causing the issue. For example:
ERROR: relation "PageContents" already existsThis tells you the specific conflict blocking the migration.
Verify that your development database matches your migration history. Use a database client (psql, MySQL CLI, or Prisma Studio) to inspect the current schema:
npx prisma studioOr connect directly:
psql $DATABASE_URL -c "\dt" # PostgreSQL: list tables
mysql -u user -p < "SHOW TABLES;" # MySQLIf you see tables or columns that shouldn't exist (created manually or by other tools), you need to remove them or document them in your migrations.
Compare your prisma/schema.prisma with your migration files:
ls -la prisma/migrations/
cat prisma/migrations/*/migration.sqlYour schema.prisma should represent the END state of all your migrations. If it doesn't, edit schema.prisma to match, then generate a new migration:
npx prisma migrate dev --name fix_schema_syncIf your database and schema are out of sync, pull the current database state into your Prisma schema:
npx prisma db pullThis introspects your actual database and updates schema.prisma. Review the changes carefully, then create a migration to document this state:
npx prisma migrate dev --name baseline_from_dbIf you're in active development and the data in your dev database doesn't matter, reset the database to a clean state:
npx prisma migrate resetThis will:
1. Drop the database
2. Recreate it
3. Run all migrations from scratch
4. Re-seed with your seed data
Warning: Only use this in development. Never run this in production.
If the error mentions "permission denied" or similar, ensure your database user has sufficient privileges:
For PostgreSQL:
ALTER USER your_user CREATEDB;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO your_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO your_user;
GRANT USAGE ON SCHEMA public TO your_user;For MySQL:
GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'localhost';
FLUSH PRIVILEGES;Alternatively, configure a separate shadow database user with full permissions.
If your hosting provider (e.g., Azure, some managed databases) doesn't allow automatic shadow database creation, specify one manually in schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}Then in your .env.local:
DATABASE_URL=postgresql://user:password@host/production_db
SHADOW_DATABASE_URL=postgresql://user:password@host/shadow_dbCreate the shadow database manually and ensure it's empty before running migrations.
If you switched git branches and have conflicting migrations in your history, use prisma migrate resolve to mark migrations as rolled back:
npx prisma migrate resolve --rolled-back migration_name_hereThen run:
npx prisma migrate devThis reconciles your migration history without forcing a full reset.
If the error persists, check for syntax issues in your latest migration file:
cat prisma/migrations/*/migration.sql | tail -20Ensure:
- File is saved as UTF-8 (not UTF-8 with BOM)
- SQL syntax is valid for your database
- Table/column names are properly quoted if needed
If you find an issue, edit the migration SQL file directly (before applying it) or delete the unapplied migration and recreate it.
Schema Drift Explanation: Prisma compares the end state of your migration history (replayed in the shadow database) against your actual development database. If they don't match, schema drift is detected. This can happen when: (1) you manually alter the database with raw SQL outside of Prisma, (2) you use prisma db push instead of migrate, or (3) migrations are applied partially. To prevent this, always use Prisma Migrate for schema changes and commit migration files to git. Cloud-Hosted Databases: Some managed databases (Heroku, Azure, DigitalOcean) have restrictions on creating/dropping databases. For these, you must either: (a) create a shadow database manually and configure shadowDatabaseUrl, or (b) use prisma db push for prototyping instead of prisma migrate dev. Git Branch Conflicts: When merging branches with different migrations, always re-run your migrations after merging. If branch A and B both added migrations independently, their order might conflict. Use git rebase or manually resolve conflicts in the migrations folder. If you have duplicate migration timestamps, rename them with unique dates.
P1013: The provided database string is invalid
The provided database string is invalid
P1000: Authentication failed against database server
Authentication failed against database server
P1010: User was denied access on the database
How to fix "P1010: User was denied access on the database" in Prisma
P5008: Usage exceeded, upgrade your plan (Accelerate)
How to fix "Usage exceeded, upgrade your plan" in Prisma Accelerate
P3021: Foreign keys cannot be created on this database
How to fix 'P3021: Foreign keys cannot be created on this database' in Prisma