How to fix P3015: Could not find the migration file in Prisma

PrismaINTERMEDIATEHIGHUpdated Dec 29, 2025ยท 176 views

Prisma migration files are missing or out of sync with your database. This error occurs when the migration directory exists but the migration.sql file is absent, often after git operations or branch switching.

Quick fix

Fixes P3015

P3015: Could not find the migration file at /Users/name/project/prisma/migrations/20250103154636_add_users_table/migration.sql. Please delete the directory or restore the migration file.
  1. Identify the problematic migration directory
  2. Check your git history for the missing migration
  3. Delete the orphaned migration directory (development only)
  4. If you need to preserve data, restore the migration file
prisma โ€” error
P3015: Could not find the migration file at /Users/name/project/prisma/migrations/20250103154636_add_users_table/migration.sql. Please delete the directory or restore the migration file.
P3015: Could not find the migration file

What this error means

The P3015 error happens when Prisma Migrate detects a migration directory in your `prisma/migrations/` folder, but the actual `migration.sql` file inside it is missing. This creates an inconsistency between your migration history and the file system. This typically occurs when: - You rolled back a git commit that included migrations - You switched between git branches with different migration histories - Migration files were deleted manually or by a file sync - Your local migrations folder is out of sync with source control Prisma tracks applied migrations in the `_prisma_migrations` database table. When it can't find the corresponding migration file, it throws P3015 because it doesn't know whether the migration was applied or needs to be applied.

Typical symptoms

  • Error message appears when running `prisma migrate dev` or `prisma migrate deploy`
  • Error path shows a specific migration directory like `20250103154636_add_users_table/migration.sql`
  • You recently switched git branches or reset to a previous commit
  • Your local migrations folder doesn't match your source control history
  • Migration commands are completely blocked

Common causes

  1. Git branch switching: Most common - you switched to a branch with different migration history, leaving orphaned migration directories.
  2. Git reset or rebase: Reverting to an earlier commit can leave migration directories without corresponding files.
  3. Manual deletion: Someone deleted migration files directly from the file system without using Prisma commands.
  4. Incomplete clone or checkout: The migration folder was partially downloaded or checked out from source control.
  5. File sync tools: Cloud sync (Dropbox, OneDrive) or git tools corrupted the migration file.

How to fix "P3015: Could not find the migration file"

1Identify the problematic migration directory

The error message will show you the exact path to the missing migration file. For example:

bash
P3015: Could not find the migration file at /Users/name/project/prisma/migrations/20250103154636_add_users_table/migration.sql. Please delete the directory or restore the migration file.

Note down the timestamp and name of the migration (e.g., 20250103154636_add_users_table).

2Check your git history for the missing migration

Look at recent commits to see if this migration was part of a branch you're switching away from:

bash
git log --oneline -- "prisma/migrations/20250103154636_add_users_table/"

If the migration appears in a previous commit that you reverted, this confirms the git branch issue.

3Delete the orphaned migration directory (development only)

The safest solution in development is to delete the empty migration directory:

bash
rm -rf prisma/migrations/20250103154636_add_users_table/

Then run:

bash
npx prisma migrate dev

Prisma will ask if you want to reset the database. In development, this is usually safe and recommended.

4If you need to preserve data, restore the migration file

If you're in production or need to preserve data, restore the migration.sql file from git:

bash
git checkout HEAD~1 -- "prisma/migrations/20250103154636_add_users_table/migration.sql"

Replace HEAD~1 with the appropriate commit that had the migration. Then run:

bash
npx prisma migrate deploy
5Reset and recreate from scratch (if multiple migrations are affected)

If multiple migrations are corrupted, consider a clean reset:

bash
# Delete all migrations (backup first!)
rm -rf prisma/migrations/

# Recreate initial migration from current schema
npx prisma migrate dev --name init

This creates a single init migration that represents your entire current schema. Use this only if you're okay losing the granular migration history.

Advanced notes

For production databases, always use prisma migrate resolve instead of deleting:

bash
# Mark the migration as rolled back so it can be reapplied
npx prisma migrate resolve --rolled-back "20250103154636_add_users_table"

# Then reapply it
npx prisma migrate deploy

Branch strategy tip: If your team frequently switches branches with different migrations, ensure everyone always commits both the migration directory AND the updated prisma/migrations/migration_lock.toml file to git. Missing the lock file causes similar issues.

Windows PowerShell issue: There's a known bug on Windows PowerShell where migration files can be created with UTF-16 LE encoding instead of UTF-8. If you created migrations on Windows, verify the encoding:

powershell
file prisma/migrations/*/migration.sql

If it shows "UTF-16 LE", convert it back to UTF-8 using a text editor or tool.

Frequently asked questions

What does "P3015" mean?
sql file inside it is missing. This creates an inconsistency between your migration history and the file system. This typically occurs when: - You rolled back a git commit that included migrations - You switched between git branches with different migration histories - Migration files were deleted manually or by a file sync - Your local migrations folder is out of sync with source control Prisma tracks applied migrations in the _prisma_migrations database table.
How do I fix "P3015"?
Prisma migration files are missing or out of sync with your database. This error occurs when the migration directory exists but the migration.sql file is absent, often after git operations or branch switching.
What causes "P3015"?
Git branch switching: Most common - you switched to a branch with different migration history, leaving orphaned migration directories. Git reset or rebase: Reverting to an earlier commit can leave migration directories without corresponding files. Manual deletion: Someone deleted migration files directly from the file system without using Prisma commands.
Is the "P3015" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading