2014-03-26 64 views
7

試圖部署我的項目使用Capistrano帽部署:遷移,我得到一個錯誤在我的database.yml上的測試別名(這只是在本地服務器上運行良好)rails4 - Psych :: BadAlias:未知的別名:test

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 

回答

9

我不相信你可以別名測試,開發和生產,因爲它們是基於你在啓動(如果環境是生產環境的分配中,生產設置將被應用)。問題是如果這樣做,黃瓜只能在測試環境中使用。

我用一個類似於下面:

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 
+0

感謝..得到它 – erwin

+1

這個答案是不正確的。 yaml文件中的別名與**沒有任何關係。當文件被加載時,它們只是快捷方式。無論您是否使用引用,加載文件後得到的數據看起來都是相同的。 – averell

+3

此外,原始的database.yml應該沒有任何問題 - 儘管調試它有點晚。我發現這個錯誤的唯一原因是因爲有人使用了'#save_load' - 默認情況下完全禁止引用。 – averell