Reputation: 1355
This is on Ruby 1.9.3 and Rails 3.2.19. I'm not super experienced with Rails. Today I started having this issue ONLY on our live server, everything works fine on the development server.
Whenever I try to give a publication model new tags, I get this error:
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column "taggings_count" does not exist
LINE 1: UPDATE "tags" SET "taggings_count" = OALESCE("taggings_count", 0) + 1 WHERE "tags"."id" = 47:
app/controllers/publications_controller.rb:162:in 'block in update'
app/controllers/publications_controller.rb:161:in 'update'
and line 162 of the controller is:
def update
@publication = Publication.find(params[:id])
if params[:clear_virtual_performances]
@publication.virtual_performances.each {|vp| vp.destroy}
end
if media_id = params["selected_media"]
pub_ids = @publication.publication_media_ids
PublicationMedia.update(@publication.publication_media_ids, [{:selected => false}] * pub_ids.length)
PublicationMedia.update(media_id, :selected => true)
end
respond_to do |format|
if @publication.update_attributes(params[:publication]) // <-------------------
expire_fragments
flash[:notice] = 'Publication was successfully updated.'
format.html { redirect_to(:action => 'show') }
format.xml { head :ok }
else
load_extra_vars_for_edit_form
Category.in_slug(params[:default_category])
format.html { render :action => "edit" }
format.xml { render :xml => @publication.errors,
:status => :unprocessable_entity }
end
end
end
However, the column "taggings_count" does not exist in tags and I don't know why it would be looking to update that in the first place. In fact, the table on has the columns: id, name, position, category_id, and tag_group_id. Here is the tag model:
class Tag < ActiveRecord::Base
has_many :taggings
belongs_to :category
belongs_to :tag_group
attr_accessible :name, :position, :category_id, :tag_group_id
end
If there is any more information I should give please let me know; it's vital that we get this fixed as soon as possible. All I need is for the error not to happen, even if that means creating a dummy column or something.
Upvotes: 3
Views: 187
Reputation: 46379
I guess you have a counter_cache
attribute defined in Tagging, something like belongs_to :publication, counter_cache: true
. That's causing the counter to automagically increment.
You can either remove the counter_cache: true
or make a migration to add the column.
Upvotes: 1