我有一个 Rails 8.0.1 应用程序 (Ruby 3.3.4),正在将其部署到 Heroku。代码推送成功,但每当我运行时:
heroku run rails db:migrate
我收到此错误:
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed
似乎 Rails 正在尝试通过本地 PostgreSQL 套接字进行连接,而不是使用 Heroku 的 Postgres 插件。在本地,使用 rails db:migrate 一切正常。在 Heroku 上,我已经运行了:
heroku addons:create heroku-postgresql:essential-0
…插件创建成功。我的 Gemfile 包括:
gem "rails", "~> 8.0", ">= 8.0.1"
gem "pg", "~> 1.5"
# ...
这是我的数据库.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: brikex2_development
test:
<<: *default
database: brikex2_test
production:
primary: &primary_production
<<: *default
database: brikex2_production
username: brikex2
password: <%= ENV["BRIKEX2_DATABASE_PASSWORD"] %>
cache:
<<: *primary_production
database: brikex2_production_cache
migrations_paths: db/cache_migrate
queue:
<<: *primary_production
database: brikex2_production_queue
migrations_paths: db/queue_migrate
cable:
<<: *primary_production
database: brikex2_production_cable
migrations_paths: db/cable_migrate
我需要帮助如何正确配置我的项目来解决问题