无法修复Active Record Pending Migration错误

时间:2017-04-20 05:26:45

标签: json rest activerecord rspec ruby-on-rails-5

我正在尝试制作一个模拟restful json api

使用此链接:

https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one

但是当我尝试运行以下命令时

捆绑exec rspec

的ActiveRecord :: PendingMigrationError

生成错误

我在堆栈溢出中尝试了许多解决方案但到目前为止没有效果

C:\ ruby​​ \ imran-api> bundle exec rspec C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/migration.rb:573:在`check_pending!':( ActiveRecord :: PendingMigrationError)

迁移正在等待处理。要解决此问题,请运行:

    bin/rails db:migrate RAILS_ENV=test

    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/migration.rb:586:in `load_schema_if_pending!'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/migration.rb:592:in `block in maintain_test_schema!'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/migration.rb:823:in `suppress_messages'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/migration.rb:597:in `method_missing'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/migration.rb:592:in `maintain_test_schema!'
    from C:/ruby/imran-api/spec/rails_helper.rb:27:in `<top (required)>'
    from C:/ruby/imran-api/spec/controllers/items_controller_spec.rb:1:in `require'
    from C:/ruby/imran-api/spec/controllers/items_controller_spec.rb:1:in `<top (required)>'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `load'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `block in load_spec_files'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `each'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `load_spec_files'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:100:in `setup'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:86:in `run'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
    from C:/Ruby23-x64/bin/rspec:22:in `load'
    from C:/Ruby23-x64/bin/rspec:22:in `<main>'

full error picture

2 个答案:

答案 0 :(得分:4)

首先运行测试环境的迁移文件:

rails db:migrate RAILS_ENV=test

答案 1 :(得分:0)

for window

首先转到bin文件夹:

cd bin

然后运行以下代码:

rails db:migrate RAILS_ENV=test