我试图部署一个使用Capistrano的Rails 5应用程序,并且我挂上了db:migrate步骤。Rails - 连接到与URL的postgres,角色不存在
具体而言,当我的脚本试图运行分贝:迁移我的错误:
ActiveRecord::NoDatabaseError: FATAL: role "admin" does not exist
我的database.yml文件看起来像这样生产块:
production:
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
url: <%= ENV['DATABASE_URL'] %>
和我的database_url的形式如下:
postgresql:://mydb_user:[email protected]/db_name
With myd b_user,mydbuser_pass和db_name用我自己的正确值替换。
里面的Postgres我可以看到我的数据库这些权限:
db_name | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres + postgres=CTc/postgres + mydb_user=CTc/postgres
我想这意味着mydb_user有必要使用我的数据库的权限。现在
,我登录的Capistrano的部署期间,用户确实有“管理员”的用户名,这使我相信,我根本不明白一些有关Postgres的角色。为什么当我通过数据库url为我已创建的特定postgres用户提供用户名和密码时,我当前登录的用户与postgres连接有什么关系?这是说我的ubuntu用户名需要匹配mydb_user才能登录?我如何解决这个特定于rails和数据库URL的错误与postgres?
你运行一个db:create,db:create:all或db:setup吗? NoDatabaseError表示您尚未创建所需的数据库。 http://stackoverflow.com/questions/25611004/rake-dbcreate-throws-database-does-not-exist-error-with-postgresql也有一些选项。我没有使用过Capistrano,所以我不知道这是怎么说的。 –
运行db:在类似的错误中创建结果。 PG :: ConnectionBad:致命:角色“管理员”不存在 – Msencenb
您是否尝试创建管理员?在postgres中,\ du将显示用户/角色。 (用户和角色现在是相同的东西。)然后,使用超级用户Createrole CreateDB Replication BypassRLS创建角色admin;好吧,那就是我用过的。 –