Baselining migration still fails
Hi, we just baselined our database from the existing database, we have ran all the scripts needed, like diffing and the 0_init, and then we marked 0_init as applied.
The issue is, with zero changes, we try to do
prisma migrate dev
and this seems to throw an error related to 0_init
even though we just marked this as resolved? I was expecting to see something along the lines of no migrations to execute?1 Reply
You opted for speed from this bot. Let's conjure up an answer right now!
If you've followed the baselining process—created the
0_init
migration with prisma migrate diff
, placed it in prisma/migrations/0_init/migration.sql
, and marked it as applied with prisma migrate resolve --applied 0_init
—but still encounter errors when running prisma migrate dev
, there are a few common issues to check:
1. File Encoding: If your migration.sql
file is not saved with UTF-8 encoding, Prisma may not recognize it, resulting in errors like "The migration 0_init could not be found." This is especially common when using editors like VSCode or Notepad++. Make sure to save the file as UTF-8 and try again. This has resolved similar issues for others (see here, discussion).
2. Migration Directory Name: Ensure the migration directory is named exactly 0_init
(or whatever you used in the resolve
command), and that the path is correct. Prisma applies migrations in lexicographic order, so 0_init
is recommended (docs).
3. Migration Lock File: If you manually created the migrations folder, ensure that prisma/migrations/migration_lock.toml
exists and is valid. This file is required for Prisma to track migrations (see here).
4. Windows/PowerShell Issues: If you are on Windows and using PowerShell, there are known issues with file encoding and path handling. Try using a different terminal or ensure your files are saved with the correct encoding (see here).
If all of the above are correct and you still see errors, please provide the exact error message. In a successful baseline, running prisma migrate dev
with no schema changes should result in "Everything is in sync" and no migrations being applied ([docs](https://www.prisma.io/docs/orm/prisma-migrate/wo
rkflows/baselining)).