PG :: ConnectionBad致命:角色" myapp"不存在

时间:2014-03-25 22:52:21

标签: ruby-on-rails postgresql heroku

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

PG::ConnectionBad
FATAL: role "myapp" does not exist

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

development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: myapp
password:

这是我的完整日志。我见过类似的问题,但他们只是含糊不清。

片段:

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 

有什么建议吗?

3 个答案:

答案 0 :(得分:12)

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

CREATE USER myapp WITH PASSWORD 'thepassword';

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

CREATE DATABASE myapp_development OWNER myapp;

答案 1 :(得分:1)

那是最好的解决方案。

sudo -u postgres createuser -s myapp

答案 2 :(得分:0)

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