prisma: migrate resolve: The migration could not be found

Bug description

Manually creating the folder “migrations” and a sub folder “whatever” and putting a “migration.sql” in it wont allow prisma migrate to resolve it.

How to reproduce

  1. have a database with whatever data in it already on your enviroment and call npx prisma db pull to create a schema.
  2. call npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > migration.sql
  3. manually create a folder inside prisma’s folder called “migrations” and another child folder called “initial”
  4. drag the migration.sql file into “initial”
  5. run npx prisma migrate status to see, prisma knows that folder exists “1 migration found”
  6. run npx prisma migrate resolve --applied "initial"
  7. get error “The migration initial could not be found”

Expected behavior

especting the “_prisma_migrations” table to be created on the db and populated with the first migration marked as applied.

Prisma information

schema was generated calling npx prisma db pull from the existing database

Environment & setup

  • OS: Windows–>
  • Database: Apache/2.4.38 (Debian) | 8.0.26 - MySQL Community Server - GPL
  • Node.js version: v14.18.3

Prisma Version

Environment variables loaded from .env
prisma                  : 4.2.0
@prisma/client          : 4.2.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 2920a97877e12e055c1333079b8d19cee7f33826
Studio                  : 0.469.0

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 5
  • Comments: 23 (5 by maintainers)

Commits related to this issue

Most upvoted comments

If you’re using VsCode and your 0_init/migration.sql is in the wrong encoding you can:

  • Open the file 0_init/migration.sql
  • Press Ctrl+Shift+p
  • Type “Change File Encoding”
  • Select “Save With Encoding”
  • Select “UTF-8”

I just had the exact same problem as the original author of the issue and I also tried all the suggestions above but nothing worked. I can however confirm that the last suggestion from @janpio worked for me. Likewise, I just opened the migration.sql file in Notepad++ and changed the Encoding to UTF-8. After that, running npx prisma migrate resolve --applied initial worked just fine.

If you’re using VsCode and your 0_init/migration.sql is in the wrong encoding you can:

  • Open the file 0_init/migration.sql
  • Press Ctrl+Shift+p
  • Type “Change File Encoding”
  • Select “Save With Encoding”
  • Select “UTF-8”

It works !

Just adding to this… I saw nowhere in the documentation that the migrations folder must be within the path of the schema file (I saw it in prisma’s code here)

So if as in my case you are trying for example to keep an structure of multiple schemas in one “schemas” folder and then have the “migrations” folder at the same level of “schemas”… that’s not currently possible as even with UTF-8 or using WSL to create the diff you’ll always get the “The migration 0_init could not be found. Please make sure that the migration exists, and that you included the whole name of the directory.” error.

So going from this:

  • schemas
    • whatever.prisma
  • migrations
    • 0_init/migration.sql

To this:

  • schemas
    • whatever.prisma
    • migrations
      • 0_init/migration.sql

Worked for me.

Hey everyone here, we have a related issue that could be relevant for some of you: Are you on Windows and using PowerShell (e.g. via VS Code or IntelliJ) to create the migration file via migrate diff, and then it fails on migrate resolve --applied? Then this could be another case of this problem here: https://github.com/prisma/prisma/issues/17558#issuecomment-1410856229

On Windows, using Powershell (which is the default in VS Code) using > foo.sql to pipe the output of a command (like for example migrate diff) creates a UTF-16 LE file instead of the expected UTF-8. In the latest release of Prisma CLI we added an option --output that can take a file name so you migrate diff ... --output foo.sql instead of using migrate diff ... > foo.sql. That should avoid the problem.

I was getting this error because of the empty migration folder. When I deleted the folder, the problem was fixed.

@ruanswanepoel This resolve to me! I really appreciate! Thanks!!!

Even when using 0_init instead of init as the name of the folder and migration? What error exactly did you get, when running which command?

It is happening with 0_init for me

Command

npx prisma migrate resolve --applied 0_init

Error:

The migration 0_init could not be found. Please make sure that the migration exists, and that you included the whole name of the directory. (example: "20201207184859_initial_migration")

as you can see in the screenshot - it is there image

I am following this guide: https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/baseline-your-database-typescript-postgres - with mysql and js thought