Getting: “Migrations are pending; run 'bin/rak

2020-02-16 07:17发布

I cloned my project. Bundled with "bundle install", then run "rake db:migrate". I am getting this error: (when I run the rails server and open my browser to localhost:3000) "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue."

I checked all migrations one by one and all were executed without errors. Also no errors were shown after the execution of "rake db:migrate".

This is what I see when I execute "rake db:migrate:status"

I am on development environment. Please let me know if you need any other information.

I also tried "bundle exec rake db:migrate", and "bundle exec rake db:migrate:reset" as "burninggramma" suggested.

Any clues what causes the error?

15条回答
ゆ 、 Hurt°
2楼-- · 2020-02-16 07:56

Running rake db:migrate RAILS_ENV=test did it for me

查看更多
倾城 Initia
3楼-- · 2020-02-16 07:56

I'm guessing the error is that you are creating a table that already exists, I had this problem before. Step 1 look into the error when you rake dv:migrate

Step 2 go to the model where this table is created

Step 3 add drop_table :[YOUR TABLE] right before the create_table :[YOUR TABLE]

Step 2 run rake db:migrate

Step 3 remove the drop_table once the your migration is done

查看更多
冷血范
4楼-- · 2020-02-16 07:57

Two reasons 'db:migrate:reset' did not work for me

1) loosing data 
2) we moved from php to rails, so we had an existing DB and the migrations were written on top of it not from the scratch

So What I tried is to update the 'scheema_migrations'(mysql) table with the list of migrations(just version values) that I was really sure were already run on my db(development), this can be lil time consuming process but it works. I would not attempt this on production though.

查看更多
成全新的幸福
5楼-- · 2020-02-16 08:03

When I executed rake test and met bug :

"rake aborted! ActiveRecord::PendingMigrationError: Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=test"

I tried and succeeded with:

rm -f db/*.sqlite3

rake db:create

RAILS_ENV=development rake db:migrate

rails s -e development
查看更多
疯言疯语
6楼-- · 2020-02-16 08:04

List your executed migrations with rake db:migrate:status and look if every migration was executed. You can try to cancel your migration with rake db:abort_if_pending_migrations and try to migrate again.

查看更多
放我归山
7楼-- · 2020-02-16 08:04

1. Maybe its default in ruby2/rails4 but have you tried: bundle exec rake db:migrate?

2. Another option would be resetting the whole database - use with CAUTION! resets all the data as well - bundle exec rake db:migrate:reset

+) I would just make sure that you are executing everything in the same development env:

RAILS_ENV=development bundle exec rake db:migrate:reset
RAILS_ENV=development bundle exec rails s
查看更多
登录 后发表回答