每次运行rake db:migrate
时,当我尝试使用rake执行任何其他操作时,会出现以下错误:
(work)doctorly:job_app$ rake
rake aborted!
ActiveRecord::PendingMigrationError:
Migrations are pending. To resolve this issue, run:
bin/rake db:migrate RAILS_ENV=test
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:393:in `check_pending!'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:406:in `load_schema_if_pending!'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:412:in `block in maintain_test_schema!'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:640:in `suppress_messages'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:417:in `method_missing'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:412:in `maintain_test_schema!'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_help.rb:19:in `<top (required)>'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/var/host/media/removable/SD Card/work/job_app/test/test_helper.rb:3:in `<top (required)>'
/var/host/media/removable/SD Card/work/job_app/test/controllers/welcome_controller_test.rb:1:in `require'
/var/host/media/removable/SD Card/work/job_app/test/controllers/welcome_controller_test.rb:1:in `<top (required)>'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:114:in `require'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:114:in `each'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:113:in `each'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
/home/doctorly/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/test_unit/testing.rake:8:in `block in <top (required)>'
Tasks: TOP => test:run
我继续收到此错误,直到我运行rake db:migrate RAILS_ENV=test
。我如何解决此问题,以便每次迁移时都不必运行第二次迁移?
答案 0 :(得分:1)
我的默认rails环境是否设置为test?
不,你要求 rails运行你的测试。
当你运行没有参数的rake
时,它会运行默认任务,使用Rails意味着运行测试。您需要设置测试环境才能运行它们。如果您不运行测试,请不要运行rake
,给它一个实际的命令。