How to delete a migration using sequalize-cli

Rahul Dagli picture Rahul Dagli · Nov 19, 2018 · Viewed 9.7k times · Source

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.

Answer

mcranston18 picture mcranston18 · Nov 19, 2018

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:

  1. Undo the latest migration: node_modules/.bin/sequelize db:migrate:undo
  2. Delete the latest migration file