概要
Railsのアプリを作りました。
Herokuに載せる前にまずはローカルでDBを「sqlite3」から「Postgresql」に変更したいと思っていますが上手くいきません。
環境
ruby 2.6.6
Rails 6.0.3
Windows 10
やったこと
①PostgreSQLのインストールを実施。下記フォルダが作成される。
「C:\Program Files\PostgreSQL\12」
②以下のようにGemfileの「gem 'sqlite3'」をコメントアウトし、「gem 'pg'」を追加し、「bundle install」を実行
Gemfile
1#gem 'sqlite3' 2gem 'pg'
③database.ymlを以下のように修正
databaseyml
1# SQLite version 3.x 2# gem install sqlite3 3# 4# Ensure the SQLite 3 gem is defined in your Gemfile 5# gem 'sqlite3' 6# 7default: &default 8 adapter: postgresql 9 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 timeout: 5000 11 12development: 13 <<: *default 14 database: appname_development 15 16# Warning: The database defined as "test" will be erased and 17# re-generated from your development database when you run "rake". 18# Do not set this db to the same as development or production. 19test: 20 <<: *default 21 database: appname_test 22 23production: 24 <<: *default 25 database: appname_production 26 username: appname 27 password: <%= ENV['APPNAME_DATABASE_PASSWORD'] %>
④PostgreSQL\12\data\pg_hba.conf」を以下のように修正
※「trust」の部分。「md5」⇒「trust」に変更。
# IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust # Allow replication connections from localhost, by a user with the # replication privilege. host replication all 127.0.0.1/32 trust host replication all ::1/128 trust
#結果
上記の対応を行い、再実施したところ、以下のエラーが発生しました。
PG::ConnectionBad FATAL: ���[��"username"�͑��݂��܂��� Extracted source (around line #58): ### Convenience alias for PG::Connection.new. def self::connect( *args ) return PG::Connection.new( *args ) end pg-1.2.3-x64 (mingw32) lib/pg.rb:58:in `initialize' pg-1.2.3-x64 (mingw32) lib/pg.rb:58:in `new' pg-1.2.3-x64 (mingw32) lib/pg.rb:58:in `connect' activerecord (6.0.2.2) lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection' activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:889:in `new_connection' activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:933:in `checkout_new_connection' activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:912:in `try_to_checkout_new_connection' activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:873:in `acquire_connection' activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:595:in `checkout' activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:439:in `connection' activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:1121:in `retrieve_connection' activerecord (6.0.2.2) lib/active_record/connection_handling.rb:238:in `retrieve_connection' activerecord (6.0.2.2) lib/active_record/connection_handling.rb:206:in `connection' activerecord (6.0.2.2) lib/active_record/migration.rb:562:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call' activesupport (6.0.2.2) lib/active_support/callbacks.rb:101:in `run_callbacks' actionpack (6.0.2.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call' web-console (4.0.2) lib/web_console/middleware.rb:132:in `call_app' web-console (4.0.2) lib/web_console/middleware.rb:28:in `block in call' web-console (4.0.2) lib/web_console/middleware.rb:17:in `catch' web-console (4.0.2) lib/web_console/middleware.rb:17:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (6.0.2.2) lib/rails/rack/logger.rb:38:in `call_app' railties (6.0.2.2) lib/rails/rack/logger.rb:26:in `block in call' activesupport (6.0.2.2) lib/active_support/tagged_logging.rb:80:in `block in tagged' activesupport (6.0.2.2) lib/active_support/tagged_logging.rb:28:in `tagged' activesupport (6.0.2.2) lib/active_support/tagged_logging.rb:80:in `tagged' railties (6.0.2.2) lib/rails/rack/logger.rb:26:in `call' sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/request_id.rb:27:in `call' rack (2.2.2) lib/rack/method_override.rb:24:in `call' rack (2.2.2) lib/rack/runtime.rb:22:in `call' activesupport (6.0.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/static.rb:126:in `call' rack (2.2.2) lib/rack/sendfile.rb:110:in `call' actionpack (6.0.2.2) lib/action_dispatch/middleware/host_authorization.rb:83:in `call' railties (6.0.2.2) lib/rails/engine.rb:526:in `call' puma (4.3.3) lib/puma/configuration.rb:228:in `call' puma (4.3.3) lib/puma/server.rb:682:in `handle_request' puma (4.3.3) lib/puma/server.rb:472:in `process_client' puma (4.3.3) lib/puma/server.rb:328:in `block in run' puma (4.3.3) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。