0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Rails8】heroku postgresのdatabase.ymlの書き方

Last updated at Posted at 2025-06-08

herokuのドキュメントには以下のように書いてますが...

# PostgreSQL. Versions 9.3 and up are supported.
#
(中略)
production:
  primary: &primary_production
    <<: *default
    database: myapp_production
    username: myapp
    password: <%= ENV["MYAPP_DATABASE_PASSWORD"] %>
  cache:
    <<: *primary_production
    database: myapp_production_cache
    migrations_paths: db/cache_migrate
  queue:
    <<: *primary_production
    database: myapp_production_queue
    migrations_paths: db/queue_migrate
  cable:
    <<: *primary_production
    database: myapp_production_cable
    migrations_paths: db/cable_migrate

これだと自分はうまくいかず、以下にするとうまくいきました
(user_name, passwordではなくurl: <%= ENV['DATABASE_URL'] %>に)

# PostgreSQL. Versions 9.3 and up are supported.
#
(中略)
production:
  primary: &primary_production
    <<: *default
    database: myapp_production
    url: <%= ENV['DATABASE_URL'] %>
  cache:
    <<: *primary_production
    database: myapp_production_cache
    migrations_paths: db/cache_migrate
  queue:
    <<: *primary_production
    database: myapp_production_queue
    migrations_paths: db/queue_migrate
  cable:
    <<: *primary_production
    database: myapp_production_cable
    migrations_paths: db/cable_migrate
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?