I'm new to rails, my background is in Django and Node.

I'm using a remote development db (provisioned by the folks at

When I do

$ bin/rails db:migrate RAILS_ENV=development

I get

rails aborted!
ActiveRecord::NoDatabaseError: FATAL: role "myname" does not exist
/home/myname/hello_world/bin/rails:9:in `require'
/home/myname/hello_world/bin/rails:9:in `'
/home/myname/hello_world/bin/spring:15:in `'
bin/rails:3:in `load'
bin/rails:3:in `


Caused by:
PG::ConnectionBad: FATAL: role "myname" does not exist
/home/myname/hello_world/bin/rails:9:in `require'
/home/myname/hello_world/bin/rails:9:in `'
/home/myname/hello_world/bin/spring:15:in `'
bin/rails:3:in `load'
bin/rails:3:in `

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

My database.yml file looks like this:

default: &default
adapter: postgresql
encoding: unicode
pool: 5

<<: *default username: <%= ENV['DEV_USER'] %>
password: <%= ENV['DEV_PASS'] %>
host: <%= ENV['DEV_HOST'] %>
database: <%= ENV['DEV_DB'] %>
url: <%= ENV['DEV_URL'] %>

<<: *default url: <%= ENV['TEST_DATABASE'] %>

<<: *default url: <%= ENV['PROD_DATABASE'] %>

I know that the environment values are set correctly. DEV_USER is not equal to myname -- it's a gibberish random string. Ideally I would like to be able to use DEV_URL (postgres://DEV_USER:[email protected]_HOST/DEV_DB) without any other parameters, but I get the same error regardless of whether I just use DEV_URL by itself or all the other auth params without DEV_URL. I feel like this is a dumb/simple fix -- can anyone point me in the right direction please?

Thank you so much!!

5 thoughts on “Trouble”

  1. fwiw the weird title is the result of me intending to write something a bit less cryptic and getting distracted after the first word

  2. Another important detail is that I had already run “`bin/rails db:setup“` without complaint before running “`bin/rails db:migrate RAILS_ENV=development“` unsuccessfully.

  3. What do you mean by “DEV_USER is not equal to myname — it’s a gibberish random string”? Is it really a random string, or is it the database username?

    Obviously the database username and password have to be correct for your database. The error:
    `ActiveRecord::NoDatabaseError: FATAL: role “myname” does not exist` is telling you that the username “myname” is not the correct username for your database, so it’s essentially throwing an authentication error.

  4. As far as bash is concerned it’s set as I would expect — confirmed by repeatedly doing echo $DEV_USER. There is no .env in the root of my project.

    Is there anywhere else that rails looks for these variables? Where does it explicitly call my local machine’s user in the event the database.yml value isn’t set?

    Thanks for your help


Leave a Comment