rails4 - Psych :: BadAlias:未知别名:test

时间:2014-03-26 14:48:43

标签: ruby-on-rails capistrano

尝试使用Capistrano cap deploy部署我的项目:migrate,我在我的database.yml上的测试别名中出错(这在本地服务器上运行正常)

development:
   database: db_dev
   adapter: mysql2
   username: xxxxxx
   password: xxxxxx
   host: localhost
   encoding: utf8

test: &test
   database: db_test
   adapter: mysql2
   username: xxxxxx
   password: xxxxxx
   host: localhost
   encoding: utf8

production:
   database: db_prod
   adapter: mysql2
   username: xxxxxxxx
   password: xxxxxxx
   host: localhost
   encoding: utf8

cucumber:
   <<: *test

控制台日志是:

           rake aborted!
   Psych::BadAlias: Unknown alias: test
   /railties-4.0.3/lib/rails/application/configuration.rb:106:in `database_configuration'
   /activerecord-4.0.3/lib/active_record/railtie.rb:175:in `block (2 levels) in <class:Railtie>'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:27:in `each'
   /activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
   /activerecord-4.0.3/lib/active_record/railtie.rb:174:in `block in <class:Railtie>'
   /railties-4.0.3/lib/rails/initializable.rb:30:in `instance_exec'
   /railties-4.0.3/lib/rails/initializable.rb:30:in `run'
   /railties-4.0.3/lib/rails/initializable.rb:55:in `block in run_initializers'
   /railties-4.0.3/lib/rails/initializable.rb:54:in `run_initializers'
   /railties-4.0.3/lib/rails/application.rb:215:in `initialize!'
   /railties-4.0.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
   /home/kadoudal/rails/swim-tech.eu/site/swimtech/releases/20140326140458/config/environment.rb:6:in `<top (required)>'
   /activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
   /activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `block in require'
   /activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
   /activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
   /railties-4.0.3/lib/rails/application.rb:189:in `require_environment!'
   /railties-4.0.3/lib/rails/application.rb:250:in `block in run_tasks_blocks'
   Tasks: TOP => db:migrate => environment

2 个答案:

答案 0 :(得分:8)

我不相信您可以根据您启动的环境分配测试,开发或生产别名(如果环境是生产环境,则会应用生产设置)。问题是,如果这样做,黄瓜只能在测试环境中使用。

我使用了类似下面的内容:

  base: &base
     adapter: mysql2
     host: address.com
     encoding: utf8
     adapter: mysql2
     username: xxxxxx
     password: xxxxxx

  development:
     database: db_dev
     <<: *base

  test:
     database: db_test
     <<: *base

  production:
     database: db_prod
     <<: *base

  cucumber:
     database: cucumber
     <<: *base

答案 1 :(得分:1)

您可以通过将aliases: true参数传递给YAML.safe_load方法来避免此问题:

YAML.safe_load(File.read('config/database.yml'), aliases: true)