سؤال

Before push my app to heroku, I tested my app in production mode, it works perfectly if its in the development mode, but in production mode I'm getting following error activerecord -3.1.11 Could not find table (ActiveRecord::Statement Invalid).

How to fix this error?

I'm sure that table 'pages' exists.

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 `<class:Page>'
    from C:/Sites/ecozap/app/models/page.rb:21:in `<top (required)>'
    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 `<top (required)>'
    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 <module:Finisher>'
    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 `<top (required)>'
    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 <main>'
    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 `<main>'
    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 <top (required)>'
    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 `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
هل كانت مفيدة؟

المحلول

Right, your table exists, but probably only in development database. It doesn't exist in production database, which is different by default.

You should either run

RAILS_ENV=production bundle exec rake db:migrate

to migrate your production database or edit database.yml file to set your production database to be the same as development database.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top