Cli: Sequelize db:migrate:undo is broken after switching workstations

Created on 18 Sep 2019  路  3Comments  路  Source: sequelize/cli

What you are doing?

I have a project with 3 migration files:

20180702221351-create-user.js
20190511205710-create-form.js
20190811205710-create-recommendation.js

I created the first 2 migrations on my primary workstation, but then I went on holiday and kept working on my secondary workstation, where I created the third migration.

When I came back to my primary workstation and pulled my new code, I found out that I can't run the migrations anymore, even though it worked fine in my other workstation.

What do you expect to happen?

I expect db:migrate and db:migrate:undo to work perfectly, as they do on my secondary workstation.

What is actually happening?

I am able to run db:migrate for my latest migration:
== 20190811205710-create-recommendation: migrated (0.041s)

I am also able to run db:migrate:undo once:
== 20190811205710-create-recommendation: reverted (0.011s)

But when I try to run db:migrate:undo again, I get this error:

ERROR: Unable to find migration: 20190511205711-create-recommendation.js

As you can see, there is a problem here. The next migration to undo should be 20190511205710-create-form.js, but instead I get 20190511205711-create-recommendation.js which is some sort of combination of my 2nd and 3rd migrations...

Does anyone know how to fix this? Thanks in advance.

__Dialect:__ postgres
__Database version:__ pg 7.4.3
__Sequelize CLI version:__ 4.0.0
__Sequelize version:__ 4.38.0

Most helpful comment

Thanks for the reply. Definitely weird, but I'm glad you found a solution. I will close for now but if anyone gets a similar issue we can reopen to investigate the cause.

All 3 comments

Where is your migration log being stored? Do you have a SequelizeMeta table in your database?

Thank you, that pushed me in the right direction to solve the problem!

# SELECT * FROM "SequelizeMeta";

                  name                   
-----------------------------------------
20180702221351-create-user.js
20190511205710-create-form.js
20190511205711-create-recommendation.js

I have no idea how I got '20190511205711-create-recommendation.js' in there when the filename is actually '20190811205710-create-recommendation.js'.

I ran UPDATE "SequelizeMeta" SET name = '20190811205710-create-recommendation.js' WHERE name = '20190511205711-create-recommendation.js'; and now it's working properly.

Therefore my issue is resolved, although I think it's still interesting to figure out why this happened in the first place.

Thanks for the reply. Definitely weird, but I'm glad you found a solution. I will close for now but if anyone gets a similar issue we can reopen to investigate the cause.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LucasBadico picture LucasBadico  路  5Comments

radglob picture radglob  路  6Comments

papb picture papb  路  5Comments

papb picture papb  路  3Comments

rmoura-92 picture rmoura-92  路  4Comments