I'm working on a migration using Sequelize. If the migration up
method throws an error, the migration is not logged in the database as having completed. So, if I run db:migrate:undo
, it instead runs down
on the previous (and working) migration. As a result, I have a half executed migration where the schema for it remains in the database because the corresponding down
method is never run by Sequelize. So, I need to either somehow force a single down
method to run (which I'm not seeing an option for). Or, I need to manually clean up my database every time I run a failing migration, which can be a real pain for complicated migrations where I'm constantly going through trial and error. Is there an easier way to doing this?
How to run Sequelize down migration for single file
Asked Answered
sequelize db:migrate:undo --name 20200409091823-example_table.js
Use this command to undo any particular migration
manually insert the migration into your migrations table so that sequelize will think it has completed.
To verify check the status of your migrations before and after you edit the table.
db:migrate:status
Everything listed as "up" is something that can go "down" and vice versa.
There is no way to do it as of now... There is an open issue for this in Sequelize cli repo
I tried something and it worked for me:
- rename your migration file and make sure it comes first alphabetically (make it the first one in migration files)
- comment code in the second migration file
- run
sequelize db:migrate
This will run only the first migration file.
Don't forget to uncomment the migration file you commented before
© 2022 - 2024 — McMap. All rights reserved.