我試圖部署一個使用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;好吧,那就是我用過的。 –