简体   繁体   中英

Deploy Ruby on Rails App to Heroku with mysql database

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM