2

我在 database.yml 中有以下内容

production:
  adapter: postgresql
  database: dbname
  host: host.compute-1.amazonaws.com
  username: user
  password: pass_word
  DATABASE_URL: postgres://user:pass_word@host.compute-1.amazonaws.com:5432/dbname

但是在 git push heroku master 上,我收到以下错误。

could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

我是否也需要对其他环境进行更改?

4

3 回答 3

3

herokudatabase.yml在部署时自动生成。

你需要 .git 忽略database.yml

您可以通过设置选择另一个数据库ENV['DATABASE_URL'] (use heroku config:add DATABASE_URL=....)

有关更多信息,请查看heroku 文档

于 2013-07-18T07:00:01.647 回答
0

DATABASE_URL 不是必需的。或者你可以查看这个http://railsapps.github.io/rails-heroku-tutorial.html

于 2013-07-18T06:57:12.303 回答
0

这个错误

could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

在推送期间发出,因为默认情况下 Rails 将启动以预编译资产,其中一部分是 Rails 试图连接到数据库。在构建期间,您的应用程序配置不存在,因此 Rails 尝试回退到使用 localhost 的默认值(不存在)。

有几种方法可以阻止这种情况的发生。一种(推荐的方式)是设置

config.assets.initialize_on_precompile = false

在你的production.rb.

第二种方法是启用user-env-compile实验室功能,允许您的 PG 配置在构建时存在。

$ heroku labs:enable user-env-compile -a <YOUR_APP_NAME>
于 2013-07-18T15:17:38.923 回答