Search code examples
ruby-on-railsrubyherokuheroku-postgres

Can't deploy Rails app to Heroku; complains about postgres when I'm not using any DB


I've built my first rails app and I'm trying to deploy it to Heroku but the app just crashed every time I push. When I try to log into the rails console, this is what is see:

Running rails console attached to terminal... up, run.6183 /app/vendor/bundle/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. Addgem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

I'm not even using any database in my app. This is what my database.yml file looks like:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#

development:

# 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:

production:

Can someone help me here?

Thanks!


Solution

  • The problem is that heroku will either rewrite database.yml or set environment variables that rails will pick up automatically.

    You need to actually stop Activerecord loading:

    To do this you replace require "rails/all" at the top of config/application.rb

    With

    require "action_controller/railtie"
    require "action_mailer/railtie"
    require "sprockets/railtie"
    require "rails/test_unit/railtie"
    

    You'll also need to remove anything in config/initializers or config/environments that references activerecord