OS: Ubuntu
OSバージョン: 18.04.2
rubyバージョン: 2.5.5
railsバージョン: Rails 5.2.3
mysqlバージョン: mysql Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using EditLine wrapper
railsでmysqlを使うためにGemfileで以下のように記述し,
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
そして,config/database.ymlを以下のように記述しました.
# MySQL. Versions 5.1.10 and up are supported. # # 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: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql2 encoding: utf8mb4 charset: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: username password: password socket: /tmp/mysql.sock development: <<: *default database: hoge_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: hoge_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: hoge_production username: hoge password: <%= ENV['HOGE_APP_DATABASE_PASSWORD'] %>
そして,rails db:migrate
をしたのですが,
rails aborted! LoadError: Error loading the 'postgresql' Active Record adapter. Missing a gem it depends on? pg is not part of the bundle. Add it to your Gemfile. /home/ubuntu/hoge_app/opinion_app/config/environment.rb:5:in `<top (required)>' /home/ubuntu/hoge_app/opinion_app/bin/rails:9:in `<top (required)>' /home/ubuntu/_app/opinion_app/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Caused by: Gem::LoadError: pg is not part of the bundle. Add it to your Gemfile. /home/ubuntu/hoge_app/opinion_app/config/environment.rb:5:in `<top (required)>' /home/ubuntu/hoge_app/opinion_app/bin/rails:9:in `<top (required)>' /home/ubuntu/hoge_app/opinion_app/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Tasks: TOP => db:migrate => db:load_config => environment (See full trace by running task with --trace)
となぜかpsqlになってしまっています.どうすればよいでしょうか?
(なお,セキュリティのため,ここに買いてあるDATABASE名やusernameは適当に変更しています)
##試したこと
MacOSでは同じプログラムでmysqlで動いたので,プログラムに問題はないと思います.
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。