使用update_attribute运行Rails 3迁移时出现只读错误
我正在尝试添加一个counter_cache,这个Rails 3迁移给我一个我似乎无法解决的错误。
迁移是
class AddItemsCountToStore< ActiveRecord的::迁移
def self.up
add_column:stores,:items_count,:integer,:default => 0
Store.reset_column_information
Store.all.each do | store |
store.update_attribute:items_count,store.items.count
结束
结束
def self.down
remove_column:stores,:items_count
结束
结束
而错误是:
== AddItemsCountToStore:迁移=========================================
- add_column(:stores,:items_count,:integer,{:default => 0})
- > 0.0680s
耙子流产了!
发生错误,此以及所有后续迁移都已取消:
items_count标记为只读
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/persistence.rb:115:在`update_attribute'中
有任何想法吗?
没有找到相关结果
已邀请:
1 个回复
蕉衫