2016-03-02 126 views
0

種子內,我創建了以下;Raking UnknownAttributeError當傾斜

post = Post.create(
    title: Faker::Lorem.sentence(20), 
    content: Faker::Lorem.paragraph, 
    publish: true, 
    administrator: administrator) 

tag = Tag.create(name: Faker::Lorem.words) 

post_tag = PostTag.create(post: post, tag: tag) 

然後,在終端內我試圖「耙db:重置」,它不工作,並顯示以下錯誤;

-- initialize_schema_migrations_table() 
    -> 0.0049s 
rake aborted! 
ActiveRecord::UnknownAttributeError: unknown attribute 'publish' for Post. 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord- 4.2.5.1/lib/active_record/attribute_assignment.rb:59:in `rescue in _assign_attribute' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord- 4.2.5.1/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:35:in `each' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:35:in `assign_attributes' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/core.rb:566:in `init_attributes' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/core.rb:281:in `initialize' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/inheritance.rb:61:in `new' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/inheritance.rb:61:in `new' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/persistence.rb:33:in `create' 
/Users/laurenwoodhams/Desktop/PROJECT/RAILS-BLOG/-t/db/seeds.rb:13:in `<top (required)>' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `block in load' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/engine.rb:547:in `load_seed' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/tasks/database_tasks.rb:250:in `load_seed' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/railties/databases.rake:183:in `block (2 levels) in <top (required)>' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/railties/databases.rake:142:in `block (2 levels) in <top (required)>' 
NoMethodError: undefined method `publish=' for #<Post:0x007f98d0073d00> 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activemodel-4.2.5.1/lib/active_model/attribute_methods.rb:433:in `method_missing' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:54:in `public_send' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:35:in `each' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:35:in `assign_attributes' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/core.rb:566:in `init_attributes' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/core.rb:281:in `initialize' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/inheritance.rb:61:in `new' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/inheritance.rb:61:in `new' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/persistence.rb:33:in `create' 
/Users/laurenwoodhams/Desktop/PROJECT/RAILS-BLOG/-t/db/seeds.rb:13:in `<top (required)>' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `block in load' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/engine.rb:547:in `load_seed' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/tasks/database_tasks.rb:250:in `load_seed' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/railties/databases.rake:183:in `block (2 levels) in <top (required)>' 
/Users/laurenwoodhams/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/railties/databases.rake:142:in `block (2 levels) in <top (required)>' 
Tasks: TOP => db:setup => db:seed 
(See full trace by running task with --trace) 

請問您爲什麼可能會推這個錯誤?

謝謝

+2

檢查'publish'列添加到您的數據庫表?您可以通過查看'schema.rb'文件來檢查相同的結果。 –

+0

Post的遷移是什麼樣的?或者,具體來說,發佈「發佈」屬性的遷移是什麼樣的? – SirUncleCid

+0

@ArupRakshit謝謝你,我檢查了我的模式文件,發現錯誤。我輸入了「pubblish」而不是「publish」。 –

回答

0

然後,終端中我試圖 「耙分貝:復位」。 。 。

嘗試運行:

rake db:migrate 
rake db:reset 

根據你的數據庫(無論何種原因)你Post對象不具有publish屬性。

當您運行rake db:reset新遷移沒有得到「遷移」。相反,它會加載模式(不包括未遷移的遷移)。


更多信息:https://stackoverflow.com/a/10302357/1026898