如何解决“角色不存在”错误?

时间:2019-05-27 08:39:45

标签: ruby-on-rails ruby heroku-postgres

我刚刚使用它创建了一个新的Ruby on rails项目,以便与Heroku一起部署

rails new -d postgresql LG_1

然后我使用rails来运行服务器并发现此错误:

role "esteban" does not exist.

我一直在寻找解决方案一个小时,但没有一个起作用。使用createuser只会给我“不存在”错误,我对Rails不太满意。

我正在使用的版本:

Ruby 2.4.4
Rails 5.2.3
Pg (gem) 1.1.4

这是我的database.yml文件(无75行注释):

default: &default
    adapter: postgresql
    encoding: unicode
    host: /var/run/postgresql
    pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
    <<: *default
    database: LG_1_development

test:
     <<: *default
     database: LG_1_test

production:
    <<: *default
    database: LG_1_production
    username: LG_1
    password: <%= ENV['LG_1_DATABASE_PASSWORD'] %>

我没有编辑此文件。

2 个答案:

答案 0 :(得分:0)

您是否为项目安装了新的宝石?

如果您这样做了,我认为您没有进行数据库迁移。

请运行以下命令。

$heroku run rake db:migrate

$heroku ps:scale web=1

$heroku ps

$heroku open

答案 1 :(得分:0)

我猜esteban是您本地计算机上的用户名,因为您没有在database.yml中为development模式设置特定的用户名和密码,而postgres在尝试打开时使用的是用户名连接到数据库。

在postgres中创建角色esteban

# go to psql console under default postgres user
psql postgres 
# create role
create role esteban SUPERUSER LOGIN;
# exit psql
\q

或在database.yml中设置正确的一个

相关问题