【问题标题】:PG::ConnectionBad: FATAL: role "***" does not existPG::ConnectionBad: FATAL: 角色“***”不存在
【发布时间】:2017-03-30 13:07:12
【问题描述】:

我的应用程序的本地版本运行良好,但我正在尝试将数据推送到我的实时应用程序。我正在运行 rails db:migrate RAILS_ENV=production 并收到 PG::ConnectionBad: FATAL: role "***" does not exist 消息。

我将 .yml 文件中的“用户名”“数据库”和“密码”作为我的 heroku postgres 插件的数据库凭据下给出的详细信息

我的 .yml 文件:

default: &default
  adapter: postgresql
  pool: 5
  timeout: 5000

development:
  adapter: postgresql
  database: postgresql-rectangular-42683
  pool: 5
  timeout: 5000
test:
  adapter: postgresql
  database: postgresql-rectangular-42683
  pool: 5
  timeout: 5000

production:
 adapter: postgresql
 encoding: utf8
 database: ***
 pool: 5
 username: ***
 password: *********
 #host: ***.***.***.*** #-> only for third party db server

【问题讨论】:

  • 你必须先创建角色或使用现有角色username: postgres
  • 如果您使用的用户名不同于postgres
  • 如果我使用用户名:postgres 并且只使用给定的数据库名称“postgresql-rectangular-42683”,那么终端不会抛出任何反馈并检查 heroku,数据库没有更新。我如何确定这是在更新我的产品数据库?特别是当我运行 ENV=production 时?
  • Heroku 不使用你的 database.yml
  • @DeepakMahakale 你完全确定吗?

标签: ruby-on-rails postgresql heroku


【解决方案1】:

Heroku 服务是动态的,并且会在其整个主机群中移动。因此,您应该避免对这些数据库凭据和配置选项进行硬编码。相反,请通过 DATABASE_URL 配置变量进行连接,该变量将代表您保持最新。 here 的文档。

当您进行这些更改并确保迁移已推送到您的 heroku 远程时,您可以通过运行 heroku run rake db:migrate -a <app name> 来完成迁移

【讨论】:

  • 这正是我最终所做的。
【解决方案2】:

参考来自 postgres 的 CREATE ROLE 命令

首选

CREATE USER foo WITH PASSWORD 'bar';

或者使用现有的 postgres 角色

production:
adapter: postgresql
encoding: utf8
database: database_development
pool: 5
username: postgres
password: *********

【讨论】:

  • Heroku Postgres 目前不支持创建角色。
猜你喜欢
  • 2014-05-04
  • 2014-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多