Failed to apply a migration
Hi lads, I am having issues pushing changes to production db and receiving P3018 Migration failed to apply because one of our dev applied a migration and then deleted it from the repo.
Can I just use
prisma db push and then resolve that problematic migration by creating correctly named folder and running prisma migrate resolve --aplied name_of_the_migration ?
Thank you upfront3 Replies
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into
#ask-ai if you get antsy for a second opinion!Do you still have the migration which was directly applied but deleted from migrations folder?
db push is not recommended for production environmentsHi Nurul,
Nope the migration file was nowhere to be found, my take is that he applied it and then deleted it even before committing to the branch.
This is what I did...
Deleted previous migration folders from the repo...
Create new migration folder baseline based on the current prisma.schema...
Commit to branch which we use to build the backend for the production app.
Ran inside the container the commands below:
- npx prisma generate
- npx prisma migrate resolve --applied <full_name_of_migration_folder>
- npx prisma generate again just for funsies
migrations applied, and no more complains for shadow database shenanigans for future pushes with the npx prisma migrate dev even on the development environment
I've had no errors nor data missing from the db, still I am not entirely sure if this is the correct way to deal with it and it surely relies heavily of what was actually applied in that missing migration...