x6iae
x6iae

Reputation: 4164

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

I am trying to run rake db:migrate in my rails app, but getting the following error:

PG::ConnectionBad: fe_sendauth: no password supplied

My database.yml is as follow:

<%
  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

the more confusing thing here is that when I try migrating my test database as follow:

rake db:migrate RAILS_ENV=test

my test database gets migrated successfully, without giving the password error.

this is very confusing, as I have more-or-less the same configuration for both test and development environment.

My first question is why is this so?

More importantly though, How do I get to overcome this?

I have tried to change password to be nothing, by using the psql console to set the password as: \password <username>, and hitting return with no input for new password, and confirmation, and then running the migration, with no success. I have also tried to run the migration while specifying the environment as: rake db:migrate RAILS_ENV=development with no success as well

What am I doing awfull, and how can I get this up?

Big thanks for all help.

PS: my OS is ubuntu

Upvotes: 1

Views: 1715

Answers (1)

x6iae
x6iae

Reputation: 4164

Whao... after searching more on stackoverflow, I got this question, which points to this documentation.

On following that, and configuring my .pgpass file with default username and password as said in the documentation, all worked fine!!!!

Although, I still do not understand why it was previously working for my test env database, but not the development env database.

Upvotes: 1

Related Questions