2

I am using MAC OS X along with postgresql installed via Homebrew. I am developing using Rails 4.2.1 and ruby 2.2.0. The connection with postgresql server is fine but for some reason every application accesses the database "kstavrou" which is my system username, as a development database and creates the rest as defined by database.yml. That is troublesome if you have more than 1 rails app.

rake db:create output:

Konstantinoss-MacBook-Pro:ecomm-intel kstavrou$ rake db:create
kstavrou already exists
ecomm_intel_test already exists

strange thing is that if I empty database.yml still connects fine to postgresql and tries to create again the database "kstavrou" executing there all the migrations, without trying to create the test database. rake db:create output:

Konstantinoss-MacBook-Pro:ecomm-intel kstavrou$ rake db:create
kstavrou already exists

database.yml


default: &default
  adapter: postgresql
  host: localhost
  encoding: utf8
  username: pguser
  password: 123456
  pool: 5

production:
  <<: *default
  database: ecomm_intel_prod

development:
  <<: *default
  database: ecomm_intel_dev

test:
  <<: *default
  database: ecomm_intel_test

  • 3
    First, I would double check to make sure your YML is well formed. You can paste it [here](http://yaml-online-parser.appspot.com/) and confirm it gets parsed as you expect. Otherwise, is `ENV['DATABASE_URL']` defined? If so, it is overwriting your `database.yml` configuration. Check out the [Rails docs](http://edgeguides.rubyonrails.org/configuring.html) for more on this (section 3.13). – steve klein Jul 21 '15 at 18:47
  • you sir are right! this was in my bash_profile (I guess from some install script): export DATABASE_URL=postgres:///$(whoami). I never thought the database url could affect the configuration! – Konstantinos Stavrou Jul 21 '15 at 19:37
  • Glad I was able to help! – steve klein Jul 21 '15 at 19:50

1 Answers1

4

Well the problem was that the ENV['DATABASE_URL'] was set (by some install script) so it was overwriting the database.yml configuration, as noted by steve klein, so I just removed it.

`export DATABASE_URL=postgres:///$(whoami)`
Community
  • 1
  • 1