activerecord -3.1.11出错无法找到表(ActiveRecord :: Statement Invalid)

在将我的应用程序推送到heroku之前,我在生产模式下测试了我的应用程序,如果它处于开发模式,它可以正常工作,但在生产模式下我得到以下错误activerecord -3.1.11无法找到表格(ActiveRecord :: Statement无效) )。

如何解决此错误?

我确信表’页’存在。

C:\Sites\ecozap>rails s -e production => Booting WEBrick => Rails 3.1.11 application starting in production on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/connection_ad apters/sqlite_adapter.rb:450:in `table_structure': Could not find table 'pages' (ActiveRecord::Statement Invalid) from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/ connection_adapters/sqlite_adapter.rb:333:in `columns' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/ connection_adapters/abstract/connection_pool.rb:95:in `block (2 levels) in initialize' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/ connection_adapters/abstract/connection_pool.rb:92:in `block in initialize' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/base.rb:712:in `yield' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/base.rb:712:in `default' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/base.rb:712:in `columns' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/base.rb:728:in `column_names' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/base.rb:741:in `column_methods_hash' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/base.rb:1118:in `all_attributes_exists?' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/base.rb:892:in `respond_to?' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/named_scope.rb:193:in `valid_scope_name?' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.1.11/lib/active_record/named_scope.rb:175:in `scope' from C:/Sites/ecozap/app/models/page.rb:22:in `' from C:/Sites/ecozap/app/models/page.rb:21:in `' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `block in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:225:in `load_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:348:in `require_or_load' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:489:in `load_missing_constant' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:181:in `block in const_missing' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:179:in `each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:179:in `const_missing' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/inflector/methods.rb:124:in `block in constantize' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/inflector/methods.rb:123:in `each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/inflector/methods.rb:123:in `constantize' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/core_ext/string/inflections.rb:43:in `constantize' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.1.11/lib/action_controller/metal/params_wrapper.rb:148:in `_default_wrap_model' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.1.11/lib/action_controller/metal/params_wrapper.rb:167:in `_set_wrapper_defaults' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.1.11/lib/action_controller/metal/params_wrapper.rb:128:in `inherited' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.1.11/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in with' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.1.11/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with' from C:/Sites/ecozap/app/controllers/pages_controller.rb:1:in `' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `block in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:225:in `load_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:348:in `require_or_load' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:302:in `depend_on' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:214:in `require_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/engine.rb:417:in `block (2 levels) in eager_load!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/engine.rb:416:in `each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/engine.rb:416:in `block in eager_load!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/engine.rb:414:in `each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/engine.rb:414:in `eager_load!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/application/finisher.rb:51:in `block in ' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/initializable.rb:30:in `instance_exec' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/initializable.rb:30:in `run' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/initializable.rb:55:in `block in run_initializers' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/initializable.rb:54:in `each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/initializable.rb:54:in `run_initializers' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/application.rb:96:in `initialize!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/railtie/configurable.rb:30:in `method_missing' from C:/Sites/ecozap/config/environment.rb:5:in `' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `block in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:223:in `block in load_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:640:in `new_constants_in' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:223:in `load_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.1.11/lib/active_support/dependencies.rb:240:in `require' from C:/Sites/ecozap/config.ru:8:in `block in ' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/builder.rb:51:in`instance_eval' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/builder.rb:51:in`initialize' from C:/Sites/ecozap/config.ru:in `new' from C:/Sites/ecozap/config.ru:in `' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/builder.rb:40:in`eval' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/builder.rb:40:in`parse_file' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/server.rb:200:in`app' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/commands/server.rb:46:in `app' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/server.rb:304:in`wrapped_app' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.3.10/lib/rack/server.rb:254:in`start' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/commands/server.rb:70:in `start' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/commands.rb:54:in `block in ' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/commands.rb:49:in `tap' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.1.11/lib/rails/commands.rb:49:in `' from script/rails:6:in `require' from script/rails:6:in `' 

是的,您的表存在,但可能只在开发数据库中。 它在生产数据库中不存在,默认情况下不同。

你应该跑

 RAILS_ENV=production bundle exec rake db:migrate 

迁移生产数据库或编辑database.yml文件以将生产数据库设置为与开发数据库相同。