PG :: ConnectionBad FATAL:角色"myapp"不存在

use*_*341 6 postgresql ruby-on-rails heroku

我可以使用postgres.app在Mac上使用postgres.app在应用内部输入rails而没有任何问题,但是,当我转到localhost:3000时,它给了我这个错误:

PG::ConnectionBad
FATAL: role "myapp" does not exist
Run Code Online (Sandbox Code Playgroud)

我一开始认为问题是database.yml文件,但是heroku docs甚至说它的方式是这样的:https://devcenter.heroku.com/articles/getting-started-with-rails4

development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: myapp
password:
Run Code Online (Sandbox Code Playgroud)

这是我的完整日志.我见过类似的问题,但他们只是模糊地与此有关.

片段:

Started GET "/" for 127.0.0.1 at 2014-03-25 16:48:31 -0600

PG::ConnectionBad (FATAL:  role "myapp" does not exist
):
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
  activerecord (4.0.2)  lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
  /Users/johncurry/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
  /Users/johncurry/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in 
Run Code Online (Sandbox Code Playgroud)

有什么建议?

Cra*_*ger 13

您似乎还没有为应用程序创建用户帐户.在psql:

CREATE USER myapp WITH PASSWORD 'thepassword';
Run Code Online (Sandbox Code Playgroud)

如果你还没有,你还需要创建一个数据库:

CREATE DATABASE myapp_development OWNER myapp;
Run Code Online (Sandbox Code Playgroud)


CWi*_*tty 0

您需要在本地计算机上创建 Postgres 用户。该角色是您的用户名。