Rails 4: Changing the "Development" database from Postgresql to Sqlite3 makes the Rails server error

Asked

Viewed 1,157 times

3

Hello.

For some reasons, I had to change my DB "Development" from Postgresql Rails back to Sqlite3. Only the page has stopped working and the error that appears in the server Rails output is this:

Started GET "/" for 127.0.0.1 at 2014-04-08 15:16:07 -0300
Started GET "/" for 127.0.0.1 at 2014-04-08 15:16:07 -0300
  ActiveRecord::SchemaMigration Load (0.1ms)  SELECT "schema_migrations".* FROM "schema_migrations"
  ActiveRecord::SchemaMigration Load (0.1ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by MedicosController#index as HTML
Processing by MedicosController#index as HTML
Completed 500 Internal Server Error in 22ms
Completed 500 Internal Server Error in 22ms

NameError (uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter):
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:228:in `const_get'
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:228:in `block in constantize'
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:224:in `each'
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:224:in `inject'
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:224:in `constantize'
  activesupport (4.0.3) lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
  activesupport (4.0.3) lib/active_support/core_ext/marshal.rb:10:in `rescue in load_with_autoloading'
  activesupport (4.0.3) lib/active_support/core_ext/marshal.rb:6:in `load_with_autoloading'
  activesupport (4.0.3) lib/active_support/message_encryptor.rb:93:in `_decrypt'
  activesupport (4.0.3) lib/active_support/message_encryptor.rb:63:in `decrypt_and_verify'
  actionpack (4.0.3) lib/action_dispatch/middleware/cookies.rb:461:in `decrypt_and_verify'
  actionpack (4.0.3) lib/action_dispatch/middleware/cookies.rb:443:in `[]'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:113:in `get_cookie'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:89:in `block in unpacked_cookie_data'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:51:in `stale_session_check!'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:88:in `unpacked_cookie_data'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:82:in `block in extract_session_id'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:51:in `stale_session_check!'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:81:in `extract_session_id'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:46:in `block in []'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:45:in `fetch'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:45:in `[]'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:67:in `id'
  rack (1.5.2) lib/rack/session/abstract/id.rb:282:in `current_session_id'
  rack (1.5.2) lib/rack/session/abstract/id.rb:288:in `session_exists?'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:140:in `exists?'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:160:in `load_for_read!'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:86:in `[]'
  turbolinks (2.2.1) lib/turbolinks/xhr_headers.rb:35:in `set_xhr_redirected_to'
  activesupport (4.0.3) lib/active_support/callbacks.rb:387:in `_run__1459366670037946371__process_action__callbacks'
  activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (4.0.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.0.3) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.0.3) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.3) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.0.3) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
  activerecord (4.0.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.0.3) lib/abstract_controller/base.rb:136:in `process'
  actionpack (4.0.3) lib/abstract_controller/rendering.rb:44:in `process'
  actionpack (4.0.3) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.3) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:80:in `call'
  actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.0.3) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.3) lib/action_dispatch/journey/router.rb:59:in `each'
  actionpack (4.0.3) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:680:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  activerecord (4.0.3) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  activerecord (4.0.3) lib/active_record/migration.rb:369:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.3) lib/active_support/callbacks.rb:373:in `_run__1602425749402505572__call__callbacks'
  activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.3) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.0.3) lib/rails/engine.rb:511:in `call'
  railties (4.0.3) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /usr/lib64/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /usr/lib64/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /usr/lib64/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'



NameError (uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter):
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:228:in `const_get'
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:228:in `block in constantize'
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:224:in `each'
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:224:in `inject'
  activesupport (4.0.3) lib/active_support/inflector/methods.rb:224:in `constantize'
  activesupport (4.0.3) lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
  activesupport (4.0.3) lib/active_support/core_ext/marshal.rb:10:in `rescue in load_with_autoloading'
  activesupport (4.0.3) lib/active_support/core_ext/marshal.rb:6:in `load_with_autoloading'
  activesupport (4.0.3) lib/active_support/message_encryptor.rb:93:in `_decrypt'
  activesupport (4.0.3) lib/active_support/message_encryptor.rb:63:in `decrypt_and_verify'
  actionpack (4.0.3) lib/action_dispatch/middleware/cookies.rb:461:in `decrypt_and_verify'
  actionpack (4.0.3) lib/action_dispatch/middleware/cookies.rb:443:in `[]'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:113:in `get_cookie'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:89:in `block in unpacked_cookie_data'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:51:in `stale_session_check!'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:88:in `unpacked_cookie_data'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:82:in `block in extract_session_id'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:51:in `stale_session_check!'
  actionpack (4.0.3) lib/action_dispatch/middleware/session/cookie_store.rb:81:in `extract_session_id'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:46:in `block in []'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:45:in `fetch'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:45:in `[]'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:67:in `id'
  rack (1.5.2) lib/rack/session/abstract/id.rb:282:in `current_session_id'
  rack (1.5.2) lib/rack/session/abstract/id.rb:288:in `session_exists?'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:140:in `exists?'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:160:in `load_for_read!'
  actionpack (4.0.3) lib/action_dispatch/request/session.rb:86:in `[]'
  turbolinks (2.2.1) lib/turbolinks/xhr_headers.rb:35:in `set_xhr_redirected_to'
  activesupport (4.0.3) lib/active_support/callbacks.rb:387:in `_run__1459366670037946371__process_action__callbacks'
  activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (4.0.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.0.3) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.0.3) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.3) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.0.3) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
  activerecord (4.0.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.0.3) lib/abstract_controller/base.rb:136:in `process'
  actionpack (4.0.3) lib/abstract_controller/rendering.rb:44:in `process'
  actionpack (4.0.3) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.3) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:80:in `call'
  actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.0.3) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.3) lib/action_dispatch/journey/router.rb:59:in `each'
  actionpack (4.0.3) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:680:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  activerecord (4.0.3) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  activerecord (4.0.3) lib/active_record/migration.rb:369:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.3) lib/active_support/callbacks.rb:373:in `_run__1602425749402505572__call__callbacks'
  activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.3) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.0.3) lib/rails/engine.rb:511:in `call'
  railties (4.0.3) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /usr/lib64/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /usr/lib64/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /usr/lib64/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'


  Rendered /usr/lib64/ruby/gems/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.6ms)
  Rendered /usr/lib64/ruby/gems/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.6ms)
  Rendered /usr/lib64/ruby/gems/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
  Rendered /usr/lib64/ruby/gems/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
  Rendered /usr/lib64/ruby/gems/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (4.5ms)
  Rendered /usr/lib64/ruby/gems/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (4.5ms)
  Rendered /usr/lib64/ruby/gems/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.6ms)
  Rendered /usr/lib64/ruby/gems/2.0.0/gems/actionpack-4.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.6ms)

I highlight this:

NameError (uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)

For some reason, it is still referencing the postgres Adapter. But my config/database.yml looks like this:

development:
  adapter: sqlite3
  database: dev_db.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: test_db.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  database: production_db
  pool: 5
  timeout: 5000

The development bank has already been changed to Sqlite.

The tests work; the console Rails works; only accessing the page gives this problem.

Any idea?

2 answers

3

Try to leave yours Gemfile as follows:

group :production, :test do
  gem 'pg'
end

group :development do
  gem 'sqlite'
end

This avoids initializing Postgres libraries in the development environment.

Then execute bundle install, execute rake db:migrate (if you haven’t already) and restart the server.

  • I’d already done it, but I hadn’t done anything.

0


Well, in order to keep working, I had to keep using Heroku’s Postgresql comic for a while. Now for some reason I got another SQL file and everything is working normally again.

I have no idea what I did differently this time.

Anyway, thank you to everyone who helped me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.