当我运行heroku run rails db:migrate
时,我收到一个错误:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/app/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/app/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/app/vendor/bundle/ruby/2.6.0/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
我已经安装了pg
宝石。这是我的配置:
# database.yml
production:
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
database: bigbig-fishfish_production
username: bigbig-fishfish
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
有什么我正在做的那显然是错的吗?为什么我收到错误?
你没有提供host
所以Rails正试图连接到本地运行的Postgres。您的数据库服务器不会在Heroku上的localhost
上。此外,您的数据库名称和用户名看起来不正确。你不能自己选择这些值。
假设您正在使用Heroku's own Postgres service,您应该使用DATABASE_URL
environment variable连接到Postgres。由于您使用的是Rails 5,因此您应该使用omit the database
, username
, and password
values completely。确保你有一个DATABASE_URL
(你应该有一个开箱即用,如果你使用Heroku Postgres)和Rails应该自动使用它。