I manually deleted a migration file name 20171125081136-create-task.js
.
After deleting the migration file, I ran this command
db:migrate:undo:all
While running this command I'm getting an error in the terminal:
ERROR: Unable to find migration: 20171125081136-create-task.js
.
Due to this error I'm stuck and not able to undo other migration files that exists.
Undoing Migrations With migration you can revert to old state by just running a command. You can use db:migrate:undo , this command will revert the most recent migration. You can revert back to the initial state by undoing all migrations with the db:migrate:undo:all command.
Click the Migrations tab to display a table containing the available migrations. For the migration to delete, click the trash icon, delete, on the right side of the table, and then select Delete migration.
To delete rows of data from your SQL table using Sequelize, you need to use the provided destroy() method. The destroy() method can be called from any Model or instance of your Model to delete rows from your table.
In your case, you must add the deleted migration file back in because Sequelize requires it to roll back your migrations. If you don't have it, you can add a blank migration file titled 20171125081136-create-task.js
. The file must have a down
function that returns a successful promise.
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return Promise.resolve()
},
down: function(queryInterface) {
return Promise.resolve()
}
};
Going forward, if you want to delete a migration:
node_modules/.bin/sequelize db:migrate:undo
I was getting the same issue an this is how I solved it:
Sequelize stores the migration history within a separate table, ex "SequelizeMeta". If you delete a migration file and no longer want to use it after, you can remove the migration rows corresponding to your migration file from the SequelizeMeta table.
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With