私はを使用してRails 3.2.6
います。カウンターキャッシュを作成しようとすると、どういうわけかこのエラーが発生します。
どうすればこれを修正できますか?私はこのアプリで同じことをしましたが、このモデルではしませんでした。
コードまたは関連付けの何が問題になっていますか?
指図 bundle exec rake db:migrate
ログ
== AddCommunityTopicsCountToCommunity: migrating =============================
-- add_column(:communities, :community_topics_count, :integer, {:default=>0})
-> 0.0635s
rake aborted!
An error has occurred, all later migrations canceled:
community_topics_count is marked as readonly
models / community.rb
...
has_many :community_topics
...
models / community_topic.rb
...
belongs_to :community, counter_cache: true
...
移行ファイル
class AddCommunityTopicsCountToCommunity < ActiveRecord::Migration
def up
add_column :communities, :community_topics_count, :integer, :default => 0
Community.reset_column_information
Community.all.each do |p|
p.update_attribute :community_topics_count, p.community_topics.length
end
end
def down
remove_column :communities, :community_topics_count
end
end