gpt4 book ai didi

ruby-on-rails - Acts_as_taggable_on 迁移失败

转载 作者:数据小太阳 更新时间:2023-10-29 08:10:33 25 4
gpt4 key购买 nike

我使用的是 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 属性没有按预期工作。谷歌似乎不是很有帮助(类似的错误报告,例如 http://www.ruby-forum.com/topic/194219 )。有什么办法可以解决吗? gem 替代品?

已解决automatic_foreign_key 与这个 gem 冲突

最佳答案

您是否修改了迁移以添加外键约束?

acts-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

关于ruby-on-rails - Acts_as_taggable_on 迁移失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5929805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com