Ruby on rails 如何在heroku上使用带rails的postgres
我在数据库中有以下内容。ymlRuby on rails 如何在heroku上使用带rails的postgres,ruby-on-rails,heroku,configuration,Ruby On Rails,Heroku,Configuration,我在数据库中有以下内容。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 ma
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?
我还需要更改其他环境吗?不需要数据库URL。或者,您可以在部署上检查这个heroku autogenerates
database.yml
您需要.git ignoredatabase.yml
您可以通过设置ENV['database\u URL'](使用heroku配置:adddatabase\u URL=..)来选择另一个数据库。
有关详细信息,请检查此错误的
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
labs特性,这将允许您的PG配置在构建时存在
$ heroku labs:enable user-env-compile -a <YOUR_APP_NAME>
$heroku实验室:启用用户环境编译-a
请从数据库中删除数据库\u URL。ymlI只是在先前收到错误后才添加了它,但是错误没有任何变化,您在git push时出现了错误,因此请粘贴git push时出现的所有错误。请同时检查并同时检查config.assets.initialize\u on\u precompile=false
请查看我们的评论