1

I'm having issues with deploying my Ruby on Rails app onto Heroku. I've set it up to the point where I would like to run the following command:

git push heroku master

Unfortunately, when I run the command I get an error that prevents me from pushing the whole app. The main line that stands out is:

Gem::LoadError: 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).

I don't use 'postgresql', I use mysql for my database adapter so I'm pretty sure adding the pg gem won't solve this issue. Where us this database adapter Specified for the database adapter?

Here is my config/database.yml file:

# MySQL.  Versions 5.0+ are recommended.
#
# Install the MYSQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem 'mysql2'
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
#
default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  database: homeworkdb
  username: root
  password: malbec32
  host: localhost
  # socket: /var/run/mysqld/mysqld.sock

development:
  <<: *default
  database: homework_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:
  <<: *default
  database: homework_test

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
#   production:
#     url: <%= ENV['DATABASE_URL'] %>
#
production:
  <<: *default
  database: homework_production
  username: homework
  password: <%= ENV['HOMEWORK_DATABASE_PASSWORD'] %>

I also have the following lines in my Gemfile:

group :production do 
    gem 'mysql2'
end
gem 'mysql2'

If anybody can see anything not right in this or if you need more information then please speak up, thanks :)

1 Answer 1

1

It looks like you need change your gemfile to conform with Heroku's production standards as they use PostgreSQL:

group :production do
  gem 'pg'
  gem 'rails_12factor', '0.0.2'
end

gem 'mysql2'

After updating your gemfile, run bundle install in your terminal. Git commit your changes and push to Heroku to see if that fixes the issue.

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

2 Comments

update: now to use Mysql on Heruku you need just to install an AddOn: elements.heroku.com/addons/cleardb
@Alessandro DS Ok, I have been searching, but no simple instruction are provided. As my understanding I should install the add-on after deploying to Heroku, should I still include the pg gem for my production environment and the postgresql adapter in my database.yml before deploying? Thanks

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.