Rake tasks seem to ignore database.yml configuration

孤街浪徒 提交于 2019-12-31 02:58:07

问题


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


回答1:


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)`


来源:https://stackoverflow.com/questions/31544547/rake-tasks-seem-to-ignore-database-yml-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!