我无法弄清楚为什么在切换到Postgresql和Rails 5.2.1后运行rake db:migrate:status
时总是出现此错误的原因
[root:7e2d33988106:~/myapp]# rake db:migrate:status 12:04AM/06.27
rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/schema_migration.rb:22:in `table_exists?'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:124:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:migrate:status
(See full trace by running task with --trace)
我到目前为止所做的事情
我已编辑pg_hba.conf
文件以显示以下内容:
local all postgres md5
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
,然后重新启动服务。没运气。同样的错误。在此之前,我遇到的第一个错误是Postgresql的密码无效,因此我不得不将其中一个“对等”选项更改为“ md5”
如果我查看我的config/database.yml
文件,则外观如下:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
encoding: unicode
username: postgres
database: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_name) %>
# username: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_user_name) %>
# password: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_password) %>
development:
<<: *default
test:
<<: *default
staging:
<<: *default
production:
<<: *default
当我使用rake
(使用EDITOR=vim rails credentials:edit
)编辑凭据时,该文件的外观如下:
# aws:
# access_key_id: 123
# secret_access_key: 345
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: <my long key redacted for stackoverflow>
database:
development:
database_name: development
database_user_name: postgres
database_password: <redacted for stackoverflow>
test:
database_name: test
database_user_name: postgres
database_password: <redacted for stackoverflow>
production:
database_name: production
database_user_name: postgres
database_password: <redacted for stackoverflow>
我觉得我已经花了几个小时钻探兔子洞了,无法弄清楚如何使这个Rails应用程序与Postgresql一起使用。
我在这里PG::ConnectionBad fe_sendauth: no password supplied看了这篇帖子,并尝试了它的建议,但没有运气,甚至在这里How to resolve the error 'fe_sendauth: no password supplied' in Rails using PostgreSQL?也没有运气。 host: ''
文件中的任何地方都没有host: 'localhost'
或config/database.yml
(我已经尝试添加它,但仍然无法正常工作),所以我不确定这是否包含任何内容在这里为我做任何事情。
还有其他建议吗?
答案 0 :(得分:1)
在production:
的{{1}}中添加用户名和密码