简体   繁体   中英

Rake db:migrate just reverted (rolled back) all the migrations

I just merged a branch and ran rake db:migrate on staging and it reverted all my migrations. (instead of migrating the new one)

I then went back to master, reloaded the db and ran migrations and again, the db got wiped out as before.

Any tips on how to debug that?

Why would db:migrate even rollback any migrations?

Any tips on how to maybe use a different command which tells rails only to grab new migrations and do up and will never roll back any migrations?

If a VERSION environment variable is set then rails will migrate to that version rather than the latest. In particular since rails calls to_i it will migrate to version 0 if it contains a non integer value. You can check this by running env (to list all environment variables) or ( echo $VERSION )

This is largely a relic from when rake didn't support passing arguments to tasks on the command line so people use to emulate them with environment variables so that you could do

rake db:migrate VERSION=xyz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM