2011-10-02 89 views
1

我剛安裝了一個Rails 3.1應用程序到我的部署服務器。rake未定義方法`[]'爲零:NilClass

當我試圖運行

sudo rake db:setup RAILS_ENV=「production」 

我得到了一個錯誤信息說

rake aborted! 
undefined method `[]' for nil:NilClass 

隨着--trace它說:

** Invoke db:setup (first_time) 
** Invoke db:create (first_time) 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
** Execute db:create 
rake aborted! 
undefined method '[]' for nil:NilClass 
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:74:in 'rescue in create_database' 
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:54:in 'create_database' 
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:44:in 'block (2 levels) in <top (required)>' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:205:in 'call' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:205:in 'block in execute' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:200:in 'each' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:200:in 'execute' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:158:in 'block in invoke_with_call_chain' 
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in 'mon_synchronize' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:151:in 'invoke_with_call_chain' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:176:in 'block in invoke_prerequisites' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:174:in 'each' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:174:in 'invoke_prerequisites' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:157:in 'block in invoke_with_call_chain' 
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in 'mon_synchronize' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:151:in 'invoke_with_call_chain' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:144:in 'invoke' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:112:in 'invoke_task'  
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in 'block (2 levels) in top_level' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in 'each' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in 'block in top_level' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:129:in 'standard_exception_handling' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:84:in 'top_level' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:62:in 'block in run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:129:in 'standard_exception_handling' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:59:in 'run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/bin/rake:32:in '<top (required)>' 
/usr/local/bin/rake:19:in 'load' 
/usr/local/bin/rake:19:in '<main>' 
Tasks: TOP => db:setup => db:create 

我的database.yml說

production: 
adapter: mysql2 
    encoding: utf8 
    reconnect: false 
    database: t_production 
    pool: 5 
    username: deploy 
    password: V 
    host: localhost 

只有1遷移和它說的:

class CreateDeals < ActiveRecord::Migration 
    def change 
    create_table :deals do |t| 
     t.string :title 
     t.text :description 
     t.string :image_url 
     t.decimal :price, :precision => 8, :scale => 2 
t.timestamps 
    end 
    end 
end 

我應該嘗試解決這一問題?我甚至不知道從哪裏開始。

回答

4

你應該修正你的陳述,雙引號是錯誤的。他們需要經常"報價。它可能會嘗試加載「production」環境的設置,這顯然不存在。

如果您使用的是正確的報價,請確保您的identation是正確的,定義看起來應該像下面這樣:

production: 
    adapter: mysql2 
    encoding: utf8 
    reconnect: false 
    database: t_production 
    pool: 5 
    username: deploy 
    password: V 
    host: localhost 
+0

只是試圖改變報價標準雙引號。也嘗試用單引號和不引號,仍然得到相同的錯誤信息。 – Castielle

+1

適配器行是否正確縮進? – Femaref

+1

謝謝!縮進是問題。我沒有意識到yaml有顯着的縮進。我還更新了耙子。 – Castielle

相關問題