我正在尝试添加一个counter_cache,这个Rails 3迁移正在给我一个我似乎无法解决的错误。
迁移
class AddItemsCountToStore < ActiveRecord::Migration 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 end end def self.down remove_column :stores, :items_count end end
,错误是:
== AddItemsCountToStore:迁移========================================= - add_column(:stores,:items_count,:integer,{:default =&gt; 0}) - &GT; 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'
有什么想法吗?