1

I'm new to Rails and after going through the Heroku tutorial I've set up a project using PostgresQL.

A friend also learning Rails followed a different tutorial which used SQLite as the database, which I've cloned.

When starting the rails server with the SQLite project, I'm continually getting an error suggesting that the project is trying to use PostgresQL and telling me to add gem pg to my Gemfile.

All I can seem to find online are various posts about migrating to PostgresQL from MySQL/SQLite/etc, but I am not looking to migrate.

My database.yml is as follows:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# 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:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

The error reported in RubyMine is:

/usr/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/Ty/Rails/TSCLunch/web/bin/rails server -b 0.0.0.0 -p 3000 -e development
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
    from /Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:50:in `establish_connection'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:27:in `each'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
    from /Users/Ty/Rails/TSCLunch/web/config/environment.rb:5:in `<top (required)>'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/Ty/.gem/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
    from /Users/Ty/Rails/TSCLunch/web/config.ru:3:in `block in <main>'
    from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
    from /Users/Ty/Rails/TSCLunch/web/config.ru:in `new'
    from /Users/Ty/Rails/TSCLunch/web/config.ru:in `<main>'
    from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
    from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
    from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
    from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:61:in `app'
    from /Users/Ty/.gem/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:139:in `log_to_stdout'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:78:in `start'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/Ty/.gem/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/Ty/Rails/TSCLunch/web/bin/rails:4:in `require'
    from /Users/Ty/Rails/TSCLunch/web/bin/rails:4:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

Process finished with exit code 1
1
  • 1
    Is there a DATABASE_URL environment variable ? (Does echo $DATABASE_URL output anything ) Commented Apr 21, 2015 at 6:03

2 Answers 2

2

You can specify adapter to the ActiveRecord in two ways.

  1. Using ENV['DATABASE_URL'] environment variable
  2. Using database.yml configuration file

If you have both config/database.yml and ENV['DATABASE_URL'] set then Rails will merge the configuration together. I think this is what causes your problem.

If it is so, you can remove your environmental variable or specify url explicitly in your database.yml

I encourage you to read the following article for more information: http://guides.rubyonrails.org/configuring.html#configuring-a-database

Sign up to request clarification or add additional context in comments.

1 Comment

This solved my issue. I'll add a note that even after doing this and reloading my .bash_profile, it still persisted. Not sure why, but once I restarted my computer it was working correctly. Thanks!
0

I'm assuming you just want to get a project that 'works' locally and NOT on heroku, regardless if it's using Postgres or SQLITE3, yeah?

Can you post a copy of your Gemfile as well? Since you followed the Heroku tutorial, it is unclear from your post what other steps you followed, except that you probably created your app by running this on the commandline:

$> rails new myapp --database=postgresql

This would add "gem 'pg'" to your Gemfile and it would create an appropriate database.yml for it. But then if you copied over the other database.yml specifying SQLITE3, now your Rails environment is confused.

If you do have 'gem pg' in your Gemfile, try the following steps:

1) in your Gemfile, remove that 'pg' line and replace it with: gem 'sqlite3'

2) do a 'bundle install' to install SQLITE3 which your cloned database.yml specifies anyways.

3) run the following command to reset your databases: $> rake db:reset

Hopefully that will get you going again. Now you should have a project that is using SQLITE3 rather than Postgres. You won't be able to deploy it to Heroku, though since they don't allow SQLITE3 for production.

If you get it working locally with SQLITE3 and later want to deploy to Heroku, they provide a simple procedure on moving back to Postgres from SQLITE3 here: https://devcenter.heroku.com/articles/sqlite3

1 Comment

Unfortunately doing a rake db:reset just threw the same exceptions. The gem pg line was not present in my Gemfile, just the gem sqlite3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.