' ActiveRecord :: PendingMigrationError迁移正在等待什么'错误意味着?

时间:2016-01-19 01:55:17

标签: ruby-on-rails debugging ruby-on-rails-4

我收到此错误:

  

ActiveRecord :: PendingMigrationError正在等待迁移。解决   这个问题,运行:bin / rake db:migrate RAILS_ENV = development

     

提取的来源(约#392行):390 391 def   check_pending!(connection = Base.connection)392加注   ActiveRecord :: PendingMigrationError if   ActiveRecord :: Migrator.needs_migration?(连接)393结束394   395 def load_schema_if_pending!

     

Rails.root:/ Users / checkkdahustle / Desktop / Full Sail / 25。高级   服务器端语言/ ASL / APP_2 / Project2 / ShoeDeals

     

应用程序跟踪|框架跟踪|完全跟踪activerecord(4.2.5)   lib / active_record / migration.rb:392:在check_pending!' activerecord (4.2.5) lib/active_record/migration.rb:373:in来电' ActionPack的   (4.2.5)lib / action_dispatch / middleware / callbacks.rb:29:在block in call' activesupport (4.2.5) lib/active_support/callbacks.rb:88:in run_callbacks ' activesupport(4.2.5)   lib / active_support / callbacks.rb:778:在_run_call_callbacks' activesupport (4.2.5) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack(4.2.5)   lib / action_dispatch / middleware / callbacks.rb:27:call' actionpack (4.2.5) lib/action_dispatch/middleware/reloader.rb:73:in来电'   actionpack(4.2.5)lib / action_dispatch / middleware / remote_ip.rb:78:in   call' actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in呼叫'   web-console(2.2.1)lib / web_console / middleware.rb:39:in call' actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in call'   railties(4.2.5)lib / rails / rack / logger.rb:38:in call_app' railties (4.2.5) lib/rails/rack/logger.rb:20:in阻止通话'的ActiveSupport   (4.2.5)lib / active_support / tagged_logging.rb:68:在block in tagged' activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in 标记的' activesupport(4.2.5)   lib / active_support / tagged_logging.rb:68:in tagged' railties (4.2.5) lib/rails/rack/logger.rb:20:in来电' actionpack(4.2.5)   lib / action_dispatch / middleware / request_id.rb:21:in call' rack (1.6.4) lib/rack/methodoverride.rb:22:in来电'机架(1.6.4)   lib / rack / runtime.rb:18:in call' activesupport (4.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' rack(1.6.4)lib / rack / lock.rb:17:in call' actionpack (4.2.5) lib/action_dispatch/middleware/static.rb:116:in call'机架(1.6.4)   lib / rack / sendfile.rb:113:在call' railties (4.2.5) lib/rails/engine.rb:518:in电话'铁路(4.2.5)   lib / rails / application.rb:165:call' rack (1.6.4) lib/rack/lock.rb:17:in来电'机架(1.6.4)   lib / rack / content_length.rb:15:in call' rack (1.6.4) lib/rack/handler/webrick.rb:88:in service'   /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:138:in   service' /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:94:in 运行'   /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in   `阻止在start_thread'

4 个答案:

答案 0 :(得分:3)

查看您发布的跟踪的第一行:

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

这正是它的意思:

  

正在等待迁移

因此,您有一些尚未运行的迁移,这意味着您的架构不是最新的。

要解决此问题,您只需运行待定迁移

即可
bundle exec rake db:migrate

如果您已经创建了数据库,那么它之前就已经运行了。如果这是您计算机上的新应用程序,则数据库尚不存在。您必须先创建一个数据库,然后按以下步骤运行迁移:

bundle exec rake db:create db:migrate

答案 1 :(得分:1)

捆绑执行rake db:migrate这将为我们提供解决方案

答案 2 :(得分:0)

rake db:migrate命令将为当前环境运行尚未运行的迁移。如果您正在开发env,则无需指定任何env。从下面的命令中,您可以运行所有尚未运行的未决迁移

对于Rails版本> 5

rails db:migrate

对于Rails版本<5

rake db:migrate

其他内容

如果要检查正在运行的迁移和正在等待的迁移,可以使用bolow命令

rails db:migrate:status

答案 3 :(得分:0)

如果所有解决方案都不适合您杀死 Rails 服务器并重新启动它,这对我有用,因为我运行 rails db:migrate:status 并没有发现任何待处理的迁移