本文介绍了在 Heroku、PostgreSQL 和 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 run rake db:migrate 时,我看到这个错误:

When I run heroku run rake db:migrate, I see this error:

耙子中止!PG::ConnectionBad: 无法连接到服务器: 没有那个文件或目录服务器是否在本地运行并接受Unix 域套接字/var/run/postgresql/.s.PGSQL.5432"上的连接?

如果我将此行添加到 database.yml:

If I add this line to database.yml:

host: localhost

再次运行迁移,我看到这个错误:

and run migration again, I see this error:

耙子中止!PG::ConnectionBad: 无法连接到服务器:连接被拒绝服务器是否在主机localhost"(127.0.0.1)上运行并接受端口 5432 上的 TCP/IP 连接?

如何解决?

推荐答案

好像你的应用没有提供数据库,你需要添加一个:

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

这篇关于在 Heroku、PostgreSQL 和 Rails 5 上运行迁移时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:06
查看更多