postgresql database migration error: PG::ConnectionBad: fe_sendauth: no password supplied

postgresql database migration error: PG::ConnectionBad: fe_sendauth: no password supplied

我正尝试在我的 rails 应用程序中 运行 rake db:migrate,但出现以下错误:

PG::ConnectionBad: fe_sendauth: no password supplied

我的database.yml如下:

<%
  branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '')
  branch = 'master' if branch.empty?
  suffix = branch == 'master' || branch.starts_with?('hotfix') ? '' : "_" + `git config --local --get offgrid.databases.#{branch.gsub(/[^a-zA-Z0-9]/,'')}`.strip
  suffix = ENV['DB_SUFFIX'] if ENV['DB_SUFFIX']
  puts "Database is 'offgrid_dev#{suffix}'" if Rails.env.development?
%>

development:
  adapter: postgresql
  database: offgrid_dev<%= suffix %>
  host: localhost
  encoding: unicode
  pool: 5
  password: 1

test:
  adapter: postgresql
  database: offgrid_test<%= suffix %><%= ENV['TEST_ENV_NUMBER'] %>
  host: localhost
  encoding: unicode
  pool: 5
  password: 1

这里更令人困惑的是,当我尝试按如下方式迁移我的测试数据库时:

rake db:migrate RAILS_ENV=test

我的测试数据库迁移成功,没有给出密码错误。

这非常令人困惑,因为我对测试和开发环境的配置大致相同。

我的第一个问题是为什么会这样?

但更重要的是,我该如何克服这个问题?

我尝试将密码更改为无,方法是使用 psql 控制台将密码设置为:\password <username>,然后点击 return 而不输入新密码,和确认,然后 运行ning 迁移,但没有成功。我还尝试 运行 迁移,同时将环境指定为:rake db:migrate RAILS_ENV=development 也没有成功

我到底在做什么,我该如何解决这个问题?

非常感谢大家的帮助。

PS: 我的 OS 是 ubuntu

哇...在 Whosebug 上搜索更多后,我得到了 this question, which points to this documentation

之后,按照 the documentation 中所述,使用默认 usernamepassword 配置我的 .pgpass 文件,一切正常!!!!

尽管如此,我仍然不明白为什么它以前适用于我的测试环境数据库,而不适用于开发环境数据库。