使用Rails 5在Heroku,PostgreSQL上运行迁移时出错 [英] Error when run migrations on Heroku, PostgreSQL with Rails 5
问题描述
我将PostgreSQL与Rails 5一起部署到Heroku中的免费应用程序。这是我在 database.yml
中的配置:
I deploy Rails 5 with PostgreSQL to free app in Heroku. This is my configuration from database.yml
:
production:
adapter: postgresql
username: root
password:
database: example
当我运行 heroku运行rake db:migrate
时,我看到此错误:
When I run heroku run rake db:migrate
, I see this error:
耙中止了!
PG :: ConnectionBad:无法连接到服务器:没有这样的文件或目录
服务器是否在本地运行并且在Unix域套接字 /var/run/postgresql/.s上接受
连接.PGSQL.5432?
rake aborted! 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"?
如果我将此行添加到 database.yml
:
host: localhost
并再次运行迁移,我看到此错误:
and run migration again, I see this error:
rake中止了!
PG :: ConnectionBad:无法连接至服务器:连接被拒绝
服务器是否在主机本地主机(127.0.0.1)上运行并在端口5432上接受
TCP / IP连接? / p>
rake aborted! PG::ConnectionBad: could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
如何解决?
推荐答案
似乎没有为您的应用程序提供数据库,您需要添加一个:
It seems like database is not provided for your app, you need to add one:
heroku addons:create heroku-postgresql
您可以通过运行以下命令来验证数据库已添加到应用程序中:
You can verify the database was added to your application by running:
heroku config --app your_app_name
这篇关于使用Rails 5在Heroku,PostgreSQL上运行迁移时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!