Search code examples
sequelize.jssequelize-cli

How to delete a migration using sequalize-cli


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.


Solution

  • 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