How to delete a migration using sequalize-cli
Asked Answered
M

4

9

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.

Manamanacle answered 19/11, 2018 at 10:53 Comment(0)
V
25

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
Vann answered 19/11, 2018 at 14:21 Comment(0)
C
5

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!

Cameliacamella answered 18/4, 2020 at 9:31 Comment(0)
H
1

The way out for me was deleting a record from the SequelizeMeta table. Below are the steps I went through:

  • SELECT ALL FROM "SequelizeMeta"

The SequelizeMeta table has one column name which contains records about all the migrations you have in your application.

  • Delete the migrations that you no longer want. DELETE FROM "SequelizeMeta" WHERE name='migration'

I hope this helps someone.

Hilaryhilbert answered 30/5, 2022 at 16:3 Comment(0)
I
0

I can across the same problem but found a way out. When we create migrations using sequelize, it creates a SequelizeMeta table in the DB. So what you can do is.

  • select * from SequelizeMeta - this will give you list of all you migrations.
  • now select the migrations you want to delete.
  • run query for delete - delete from table_name [where clause]

Solved my issue hope so will solve yours too. happy coding.

Identity answered 30/6, 2021 at 7:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.