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
- have a database with whatever data in it already on your enviroment and call
npx prisma db pullto create a schema. - call
npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > migration.sql - manually create a folder inside prisma’s folder called “migrations” and another child folder called “initial”
- drag the migration.sql file into “initial”
- run
npx prisma migrate statusto see, prisma knows that folder exists “1 migration found” - run
npx prisma migrate resolve --applied "initial" - 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
- Change import path — committed to charlesausejojr/labangon-wellness-hub by charlesausejojr 2 years ago
If you’re using VsCode and your
0_init/migration.sqlis in the wrong encoding you can:0_init/migration.sqlI 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.sqlfile in Notepad++ and changed the Encoding to UTF-8. After that, runningnpx prisma migrate resolve --applied initialworked just fine.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:
To this:
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 onmigrate resolve --applied? Then this could be another case of this problem here: https://github.com/prisma/prisma/issues/17558#issuecomment-1410856229On Windows, using Powershell (which is the default in VS Code) using
> foo.sqlto pipe the output of a command (like for examplemigrate diff) creates a UTF-16 LE file instead of the expected UTF-8. In the latest release of Prisma CLI we added an option--outputthat can take a file name so youmigrate diff ... --output foo.sqlinstead of usingmigrate 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!!!
It is happening with 0_init for me
Command
npx prisma migrate resolve --applied 0_initError:
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
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