简体   繁体   English

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

[英]rails4 - Psych::BadAlias: Unknown alias: test

trying to deploy my project using Capistrano cap deploy:migrate , I get an error in my database.yml on the test alias ( which is just running fine on local server)尝试使用 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

the console log is :控制台日志是:

           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

I don't believe you can alias test, development, or production as they are assigned based on the environment you boot in (if environment is production, the production settings will be applied).我不相信您可以为测试、开发或生产设置别名,因为它们是根据您启动的环境分配的(如果环境是生产环境,则将应用生产设置)。 The issue is that if this were to work, cucumber would only be usable in the test environment.问题是,如果这行得通,黄瓜将只能在测试环境中使用。

I used something akin to the below:我使用了类似于下面的东西:

  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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM