Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such column: taggings_count #57

Closed
ZirconCode opened this issue Apr 14, 2014 · 2 comments
Closed

No such column: taggings_count #57

ZirconCode opened this issue Apr 14, 2014 · 2 comments

Comments

@ZirconCode
Copy link
Contributor

I set up blogit as per the instructions, however when I try to create my first post, I get the following error:

ActiveRecord::StatementInvalid in Blogit::PostsController#create

SQLite3::SQLException: no such column: taggings_count: UPDATE "tags" SET "taggings_count" = COALESCE("taggings_count", 0) + 1 WHERE "tags"."id" = 1

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"IKRelkWfThMuzD51E72MFiot+vaCPCefCdTh/u9NGwI=",
 "post"=>{"title"=>"I love bananas",
 "body"=>"They are awesome\r\n\r\ntest\r\n---\r\n\r\n\r\nmarkdown?",
 "tag_list"=>"fruit,
 love,
 me"},
 "commit"=>"Create Post"}

I am using Rails 3.2.11 with blogit-0.8.0.
I restarted the server a few times and also ran rake db:migrate.

Thank You.

Full Error:

Started POST "/blog/posts" for 127.0.0.1 at 2014-04-14 17:16:59 +0200
Processing by Blogit::PostsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"IKRelkWfThMuzD51E72MFiot+vaCPCefCdTh/u9NGwI=", "post"=>{"title"=>"I love bananas", "body"=>"They are awesome\r\n\r\ntest\r\n---\r\n\r\n\r\nmarkdown?", "tag_list"=>"fruit, love, me"}, "commit"=>"Create Post"}
  Admin Load (0.2ms)  SELECT "admins".* FROM "admins" WHERE "admins"."id" = 1 LIMIT 1
  ActsAsTaggableOn::Tag Load (0.1ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" IS NULL AND "taggings"."taggable_type" = 'Blogit::Post' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
   (0.0ms)  begin transaction
  SQL (5.7ms)  INSERT INTO "blog_posts" ("blogger_id", "blogger_type", "body", "comments_count", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)  [["blogger_id", 1], ["blogger_type", "Admin"], ["body", "They are awesome\r\n\r\ntest\r\n---\r\n\r\n\r\nmarkdown?"], ["comments_count", 0], ["created_at", Mon, 14 Apr 2014 15:17:00 UTC +00:00], ["title", "I love bananas"], ["updated_at", Mon, 14 Apr 2014 15:17:00 UTC +00:00]]
  ActsAsTaggableOn::Tag Load (0.1ms)  SELECT "tags".* FROM "tags" WHERE (LOWER(name) = LOWER('fruit') OR LOWER(name) = LOWER('love') OR LOWER(name) = LOWER('me'))
  ActsAsTaggableOn::Tag Exists (0.1ms)  SELECT 1 AS one FROM "tags" WHERE "tags"."name" = 'fruit' LIMIT 1
  SQL (0.1ms)  INSERT INTO "tags" ("name") VALUES (?)  [["name", "fruit"]]
  ActsAsTaggableOn::Tag Exists (0.1ms)  SELECT 1 AS one FROM "tags" WHERE "tags"."name" = 'love' LIMIT 1
  SQL (0.0ms)  INSERT INTO "tags" ("name") VALUES (?)  [["name", "love"]]
  ActsAsTaggableOn::Tag Exists (0.1ms)  SELECT 1 AS one FROM "tags" WHERE "tags"."name" = 'me' LIMIT 1
  SQL (0.0ms)  INSERT INTO "tags" ("name") VALUES (?)  [["name", "me"]]
  ActsAsTaggableOn::Tag Load (0.1ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 1 AND "taggings"."taggable_type" = 'Blogit::Post' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
  ActsAsTaggableOn::Tagging Exists (0.1ms)  SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 1 AND "taggings"."taggable_type" = 'Blogit::Post' AND "taggings"."taggable_id" = 1 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL) LIMIT 1
  SQL (0.3ms)  INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES (?, ?, ?, ?, ?, ?, ?)  [["context", "tags"], ["created_at", Mon, 14 Apr 2014 15:17:00 UTC +00:00], ["tag_id", 1], ["taggable_id", 1], ["taggable_type", "Blogit::Post"], ["tagger_id", nil], ["tagger_type", nil]]
  ActsAsTaggableOn::Tag Load (0.1ms)  SELECT "tags".* FROM "tags" WHERE "tags"."id" = 1 LIMIT 1
  SQL (0.2ms)  UPDATE "tags" SET "taggings_count" = COALESCE("taggings_count", 0) + 1 WHERE "tags"."id" = 1
SQLite3::SQLException: no such column: taggings_count: UPDATE "tags" SET "taggings_count" = COALESCE("taggings_count", 0) + 1 WHERE "tags"."id" = 1
   (0.1ms)  rollback transaction
Completed 500 Internal Server Error in 336ms


ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: taggings_count: UPDATE "tags" SET "taggings_count" = COALESCE("taggings_count", 0) + 1 WHERE "tags"."id" = 1):
  sqlite3 (1.3.9) lib/sqlite3/database.rb:91:in `initialize'
  sqlite3 (1.3.9) lib/sqlite3/database.rb:91:in `new'
  sqlite3 (1.3.9) lib/sqlite3/database.rb:91:in `prepare'
  activerecord (3.2.11) lib/active_record/connection_adapters/sqlite_adapter.rb:246:in `block in exec_query'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
  activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
  activerecord (3.2.11) lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query'
  activerecord (3.2.11) lib/active_record/connection_adapters/sqlite_adapter.rb:268:in `exec_delete'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:96:in `update'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `update'
  activerecord (3.2.11) lib/active_record/relation.rb:294:in `update_all'
  activerecord (3.2.11) lib/active_record/relation.rb:278:in `update_all'
  activerecord (3.2.11) lib/active_record/querying.rb:7:in `update_all'
  activerecord (3.2.11) lib/active_record/counter_cache.rb:84:in `update_counters'
  activerecord (3.2.11) lib/active_record/locking/optimistic.rb:166:in `update_counters'
  activerecord (3.2.11) lib/active_record/counter_cache.rb:103:in `increment_counter'
  activerecord (3.2.11) lib/active_record/associations/builder/belongs_to.rb:30:in `block in add_counter_cache_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__820720759__create__451311992__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  activerecord (3.2.11) lib/active_record/callbacks.rb:268:in `create'
  activerecord (3.2.11) lib/active_record/persistence.rb:348:in `create_or_update'
  activerecord (3.2.11) lib/active_record/callbacks.rb:264:in `block in create_or_update'
  activesupport (3.2.11) lib/active_support/callbacks.rb:436:in `_run__820720759__save__451311992__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  activerecord (3.2.11) lib/active_record/callbacks.rb:264:in `create_or_update'
  activerecord (3.2.11) lib/active_record/persistence.rb:104:in `save!'
  activerecord (3.2.11) lib/active_record/validations.rb:56:in `save!'
  activerecord (3.2.11) lib/active_record/attribute_methods/dirty.rb:33:in `save!'
  activerecord (3.2.11) lib/active_record/transactions.rb:264:in `block in save!'
  activerecord (3.2.11) lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
  activerecord (3.2.11) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (3.2.11) lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
  activerecord (3.2.11) lib/active_record/transactions.rb:264:in `save!'
  activerecord (3.2.11) lib/active_record/associations/has_many_association.rb:14:in `insert_record'
  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:436:in `block (2 levels) in create_record'
  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:344:in `add_to_target'
  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:434:in `block in create_record'
  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:149:in `block in transaction'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
  activerecord (3.2.11) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:148:in `transaction'
  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:433:in `create_record'
  activerecord (3.2.11) lib/active_record/associations/collection_association.rb:123:in `create!'
  activerecord (3.2.11) lib/active_record/associations/collection_proxy.rb:46:in `create!'
  acts-as-taggable-on (3.1.1) lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:397:in `block (2 levels) in save_tags'
  acts-as-taggable-on (3.1.1) lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:396:in `each'
  acts-as-taggable-on (3.1.1) lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:396:in `block in save_tags'
  acts-as-taggable-on (3.1.1) lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:350:in `each'
  acts-as-taggable-on (3.1.1) lib/acts_as_taggable_on/acts_as_taggable_on/core.rb:350:in `save_tags'
  activesupport (3.2.11) lib/active_support/callbacks.rb:427:in `_run__954643570__save__451311992__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  activerecord (3.2.11) lib/active_record/callbacks.rb:264:in `create_or_update'
  activerecord (3.2.11) lib/active_record/persistence.rb:84:in `save'
  activerecord (3.2.11) lib/active_record/validations.rb:50:in `save'
  activerecord (3.2.11) lib/active_record/attribute_methods/dirty.rb:22:in `save'
  activerecord (3.2.11) lib/active_record/transactions.rb:259:in `block (2 levels) in save'
  activerecord (3.2.11) lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
  activerecord (3.2.11) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (3.2.11) lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
  activerecord (3.2.11) lib/active_record/transactions.rb:259:in `block in save'
  activerecord (3.2.11) lib/active_record/transactions.rb:270:in `rollback_active_record_state!'
  activerecord (3.2.11) lib/active_record/transactions.rb:258:in `save'
  blogit (0.8.0) app/controllers/blogit/posts_controller.rb:58:in `create'
  actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.2.11) lib/active_support/callbacks.rb:425:in `_run__898640690__process_action__92572029__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
  actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.11) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `call'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in `call'
  journey (1.0.4) lib/journey/router.rb:68:in `block in call'
  journey (1.0.4) lib/journey/router.rb:56:in `each'
  journey (1.0.4) lib/journey/router.rb:56:in `call'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
  railties (3.2.11) lib/rails/engine.rb:479:in `call'
  railties (3.2.11) lib/rails/railtie/configurable.rb:30:in `method_missing'
  journey (1.0.4) lib/journey/router.rb:68:in `block in call'
  journey (1.0.4) lib/journey/router.rb:56:in `each'
  journey (1.0.4) lib/journey/router.rb:56:in `call'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `catch'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.5) lib/rack/etag.rb:23:in `call'
  rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
  rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__236821733__call__451311992__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.11) lib/rails/engine.rb:479:in `call'
  railties (3.2.11) lib/rails/application.rb:223:in `call'
  rack (1.4.5) lib/rack/content_length.rb:14:in `call'
  railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
  /usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
@ZirconCode
Copy link
Contributor Author

Everything else works when leaving the tags field blank.
The problem seems to be with the acts-as-taggable gem. I am using version 3.1.1.

My ActsAsTaggableOnMigration doesn't contain a taggings_count column:

# This migration comes from blogit (originally 20110814103306)
class ActsAsTaggableOnMigration < ActiveRecord::Migration
  def self.up
    create_table :tags do |t|
      t.string :name
    end

    create_table :taggings do |t|
      t.references :tag

      # You should make sure that the column created is
      # long enough to store the required class names.
      t.references :taggable, :polymorphic => true
      t.references :tagger, :polymorphic => true

      t.string :context

      t.datetime :created_at
    end

    add_index :taggings, :tag_id
    add_index :taggings, [:taggable_id, :taggable_type, :context]
  end

  def self.down
    drop_table :taggings
    drop_table :tags
  end
end

I'm not quite sure how to fix this.

@ZirconCode
Copy link
Contributor Author

I've solved the issue by pulling the migrations from:
https://github.com/mbleigh/acts-as-taggable-on/tree/master/db/migrate

Apparently the acts-as-taggable-on gem has added two new migrations in newer versions: AddMissingUniqueIndices & AddTaggingsCounterCacheToTags

I have created a pull request (#58) which should fix this issue. This is my very first pull request, please tell me if I lack any conventions or made a mistake.

Thank You

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant