3

私は Rails 3.0.6/Ruby 1.8.7 を使用しており、acts_as_taggable_on (2.0.6) gem を動作させようとしましたが、デフォルトの移行では失敗するようです。ログ:

==  ActsAsTaggableOnMigration: migrating ======================================
-- create_table(:tags)
   -> 0.3175s
-- create_table(:taggings)
rake aborted!
An error has occurred, all later migrations canceled:

Mysql2::Error: Can't create table 'project_development.taggings' (errno: 150): 
CREATE TABLE `taggings` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, 
`tag_id` int(11), `taggable_id` int(11), `taggable_type` varchar(255), `tagger_id` 
int(11), `tagger_type` varchar(255), `context` varchar(255), `created_at` datetime, 
FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`), FOREIGN KEY (`taggable_id`) REFERENCES 
`taggables` (`id`), FOREIGN KEY (`tagger_id`) REFERENCES `taggers`    (`id`)) ENGINE=InnoDB

したがって、 :polymorphic => true 属性が意図したとおりに機能しないようです。Google はあまり役に立たないようです (同様のバグが報告されています。例: http://www.ruby-forum.com/topic/194219 )。それを修正する方法はありますか?宝石の代替品?

解決済み automatic_foreign_key がこの gem と競合する

4

1 に答える 1

1

外部キー制約を追加するために移行を変更しましたか?

act-as-taggable-on 2.0.6 で提供されている移行は、次のようになります。

class ActsAsTaggableOnMigration < ActiveRecord::Migration
      def self.up
        create_table :tags do |t|
          t.column :name, :string
        end

        create_table :taggings do |t|
          t.column :tag_id, :integer
          t.column :taggable_id, :integer
          t.column :tagger_id, :integer
          t.column :tagger_type, :string

          # You should make sure that the column created is
          # long enough to store the required class names.
          t.column :taggable_type, :string
          t.column :context, :string

          t.column :created_at, :datetime
        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
于 2011-05-08T22:55:58.013 に答える