前提・実現したいこと
ruby on railsでアプリを作っております。
rails new...でアプリを作成した時にデフォルトで入っていたSQLiteを使っていたのですが、本番環境にデプロイするにあたりPostgreSQLに変更したいと思っています。その中でエラーが発生したので、解決してこの作業を完了させたいです。
現状としては、
- コンソールで
rails db
をしたところpsql (11.1)
と出てきたので、postgreSQLのデータベースに変更できたと思われる - postgreSQLのコンソールで存在するテーブルを確認したら、SQLiteで作成した複数のテーブルが存在していた。
- あとはデータベースとアプリを接続できれば作業完了出来そう
エラー解決にあたり、ググりを重ねた結果立てられた仮説としては以下なのですが、具体的な対応策が探し出せず困っております。。
- アプリがデータベースに接続できていない?
- 原因はActiveRecordがちゃんと使える状態でないこと?
- ちゃんと使える状態にするために何かコードを書く必要がある?
発生している問題・エラーメッセージ
ActiveRecord::ConnectionNotEstablished No connection pool with 'primary' found.
該当のソースコード
config/database.yml
ruby
1default: &default 2 adapter: postgresql 3 encoding: unicode 4 pool: 5 5 timeout: 5000 6 username: (usernameを記載) 7 password: (passwordを記載) 8 host: localhost 9 10development: 11 <<: *default 12 database: db/development_postgresql 13 14# Warning: The database defined as "test" will be erased and 15# re-generated from your development database when you run "rake". 16# Do not set this db to the same as development or production. 17test: 18 <<: *default 19 database: db/test_postgresql 20 21production: 22 <<: *default 23 database: db/production_postgresql
config/application.rb
ruby
1require_relative 'boot' 2 3require 'rails/all' 4 5# Require the gems listed in Gemfile, including any gems 6# you've limited to :test, :development, or :production. 7Bundler.require(*Rails.groups) 8 9module SuppleApp 10 class Application < Rails::Application 11 # Initialize configuration defaults for originally generated Rails version. 12 config.load_defaults 5.2 13 14 # Settings in config/environments/* take precedence over those specified here. 15 # Application configuration can go into files in config/initializers 16 # -- all .rb files in that directory are automatically loaded after loading 17 # the framework and any gems in your application. 18 end 19end
試したこと
- ActiveRecordとアプリを接続するためにconfig/database.ymlのファイルに以下を書き加えた。しかしエラー解決せず。
ruby
1require "active_record" 2 3config = YAML.load_file( './database.yml' ) 4ActiveRecord::Base.establish_connection(config["db"]["development"])
- ActiveRecordとアプリを接続するためにconfig/database.ymlのファイルに以下を書き加えた。(上記のコードは一緒に記載していない)しかしエラー解決せず。
ruby
1require active_record/railtie
補足情報(FW/ツールのバージョンなど)
- Rails 5.2.2
- psql 11.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。