Migration Modified After Applied (but checksums are the same)
I have not ad any issues with my procedures yet, but today when I went to modify my chema and generate a new migration, I got the following
However, these are migrations that have been run a long time ago. I verified the checksum of my migration.sql files and the value stored in the db. They are the same. How do I get past this?
7 Replies
Skipping coffee for instant knowledge! Let's brew that AI answer now.
This issue with migrations being reported as modified despite having matching checksums is a known problem in Prisma Migrate. Let me explain what might be happening and how to resolve it.
Why This Happens
Based on the knowledge sources, this error can occur for several reasons:
- Line ending differences (CRLF vs LF) between different operating systems
- Git configuration settings that transform line endings
- Issues with rolled-back migrations that were later modified and reapplied
- Discrepancies in how Prisma tracks migration history
Solutions
Here are some approaches to resolve this issue:
1. Use the migrate resolve command
You can try using the
prisma migrate resolve
command to tell Prisma that these migrations have been properly applied:
2. Manual database fix
If the above doesn't work, you can manually update the migration records in the database:
1. Connect to your SQL Server database
2. Update the checksums in the _prisma_migrations
table to match the current files
3. Generate and update checksums
You can generate the correct checksums and update them in the database:
This script will recalculate checksums for all migrations and update them in the database Github Issue #12666.
4. Ensure consistent line endings
To prevent this issue in the future, consider adding a .gitattributes
file to your project with:
This will ensure consistent line endings across different operating systems Github Issue #7077.
Important Note
Prisma's documentation strongly advises against editing or deleting migrations that have already been applied, as this can lead to inconsistencies between environments. If you need to make changes, it's generally better to create new migrations rather than modifying existing ones Prisma Docs.wouldn't different line endings cause a different checksum?
In this case, my checksums are the same, not different.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Hey 👋
Did this error start occurring randomly, or after a prisma version upgrade?
Do you get this error when you are trying to create a new migration with
npx prisma migrate dev
command?yes I did upgrad prisma
@Nurul sorry I misread your comment/question. I got the error randomly, I then tried to upgrade prisma in order to see if that would fix it; it did not.
And yes, I am getting the error when running
pnpm prisma migrate dev
and with --create-only
First just backup u r db .......
And just do like below
Yes ...
To solve this just generate new checksum copy and paste it in db checksum.....
But now whatever that file will be skip.....
For example u have generate checksum for
J file as y
Then j files migration will be skipped automatically.....
And new migration will be created
https://discord.com/channels/937751382725886062/1342542831247560848
@hari_narayan the checksum already appears to be the same.
@Nurul any follow up on this?