database.yml 和引用不起作用 [英] database.yml &references not working

查看:22
本文介绍了database.yml 和引用不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们刚刚将我们的虚拟机升级到我认为相同的 ruby​​ 配置(通过 RVM...Ruby 1.9.2、Rails 3.0.7、DataMapper 1.1.0).最大的不同是我们从 MySQL 5.0 升级到 5.1.

We just upgraded our virtual machines to what I thought was an identical ruby configuration (via RVM... Ruby 1.9.2, Rails 3.0.7, DataMapper 1.1.0). The biggest difference was that we went from MySQL 5.0 to 5.1.

由于某种原因,在我们的旧虚拟机上运行的完全相同的 code/database.yml 现在在我们的新虚拟机上尝试连接到数据库时失败了.

For some reason, the exact same code/database.yml that was working on our old VMs now fails on our new ones at the point it tries to connect to the database.

问题在于这个 YAML:

The issue is that this YAML:

mysql_defaults: &mysql_defaults
  adapter: mysql
  encoding: UTF-8
  username: user
  password: pass
  host: localhost

development:
  <<: *mysql_defaults
  database: devdb

production:
  <<: *mysql_defaults
  database: productiondb
  host: master.db.site.com

只是扩展到:

  "mysql_defaults" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "development" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "production" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  }

代替:

  "mysql_defaults" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "development" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost",
    "database"=>"devdb"
  },
  "production" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"master.db.site.com",
    "database"=>"productiondb"
  }

以前有人经历过吗?

根据 Gemfile.lock(我删除它并再次运行 bundle install,只是为了保持理智),所有已安装的依赖项都是相同的(即 Gemfile.lock 在旧设置和新设置之间没有区别).database.yml 也没有.

According to Gemfile.lock (I deleted it and ran bundle install again, just for sanity's sake), all the installed dependencies are the same (i.e. the Gemfile.lock does not diff between the old and the new setup). Nor does the database.yml.

推荐答案

Psych 是新的 YAML 解析器,它可能更好,但不能合并哈希键.

Psych is the new YAML parser which is presumably better but can't merge hash keys.

这应该会有所帮助http://pivotallabs.com/users/mkocher/blog/articles/1692-yaml-psych-and-ruby-1-9-2-p180-here-there-be-dragons

这篇关于database.yml 和引用不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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