Ruby on rails PG::ConnectionBad:无法连接到服务器(heroku)
我可以推到heroku很好。。但是,当我运行rake时,会出现以下错误: PG::ConnectionBad:无法连接到服务器 我可以在本地运行,所以不太清楚为什么我在推heroku时遇到问题-任何帮助都会很好 我怀疑这与我的database.yml文件有关:Ruby on rails PG::ConnectionBad:无法连接到服务器(heroku),ruby-on-rails,heroku,Ruby On Rails,Heroku,我可以推到heroku很好。。但是,当我运行rake时,会出现以下错误: PG::ConnectionBad:无法连接到服务器 我可以在本地运行,所以不太清楚为什么我在推heroku时遇到问题-任何帮助都会很好 我怀疑这与我的database.yml文件有关: # SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3'
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
您不应将database.yml提交到heroku:
When Rails applications are deployed to Heroku a database.yml file is
automatically generated for your application that configures
ActiveRecord to use a PostgreSQL connection and to connect to the
database located at DATABASE_URL. This behavior is only needed up to
Rails 4.1. Any later version contains direct support for specifying a
connection URL and configuration in the database.yml so we do not have
to overwrite it.
阅读相关内容。我怎么能不提交此文件?请将您的database.yml重命名为其他文件。将更改提交到您的存储库中。这将使你的heroku应用程序正常工作。在根文件夹中有一个.gitignore文件。编辑此文件并将/config/database.yml添加到其中。在修改.gitignore之后,您可以将该文件重命名回database.yml,因为现在它被git忽略了。您可以根据需要为它提供扩展名。请记住,在将更改提交给heroku并将这一行/config/database.yml添加到.gitignore中后,将其发回database.yml。为了让应用程序在本地机器上工作,您必须这样做。它只会在Rails 5上进行引导循环
When Rails applications are deployed to Heroku a database.yml file is
automatically generated for your application that configures
ActiveRecord to use a PostgreSQL connection and to connect to the
database located at DATABASE_URL. This behavior is only needed up to
Rails 4.1. Any later version contains direct support for specifying a
connection URL and configuration in the database.yml so we do not have
to overwrite it.