Rake 任务似乎忽略了 database.yml 配置 [英] Rake tasks seem to ignore database.yml configuration

查看:47
本文介绍了Rake 任务似乎忽略了 database.yml 配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MAC OS X 以及通过 Homebrew 安装的 postgresql.我正在使用 Rails 4.2.1 和 ruby​​ 2.2.0 进行开发.与 postgresql 服务器的连接很好,但由于某种原因,每个应用程序都访问数据库kstavrou",这是我的系统用户名,作为开发数据库,​​并创建由 database.yml 定义的其余部分.如果您有 1 个以上的 Rails 应用,那就麻烦了.

耙数据库:创建输出:

<前>Konstantinoss-MacBook-Pro:ecomm-intel kstavrou$ rake db:createkstavrou 已经存在ecomm_intel_test 已经存在

奇怪的是,如果我清空 database.yml 仍然可以很好地连接到 postgresql 并尝试再次创建在那里执行所有迁移的数据库kstavrou",而不尝试创建测试数据库.耙数据库:创建输出:

<前>Konstantinoss-MacBook-Pro:ecomm-intel kstavrou$ rake db:createkstavrou 已经存在

数据库.yml<预>

<代码>默认值:&default适配器:postgresql主机:本地主机编码:utf8用户名:pguser密码:123456池:5生产:<<:*默认数据库:ecomm_intel_prod发展:<<:*默认数据库:ecomm_intel_dev测试:<<:*默认数据库:ecomm_intel_test

解决方案

嗯,问题是 ENV['DATABASE_URL'] 被设置(由一些安装脚本)所以它覆盖了 database.yml 配置,正如所指出的steve klein,所以我刚刚删除了它.

<前>`导出DATABASE_URL=postgres:///$(whoami)`

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

解决方案

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

这篇关于Rake 任务似乎忽略了 database.yml 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆