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 2 years ago
  • Reactions: 3
  • Comments: 20 (5 by maintainers)

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 !

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

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