【发布时间】:2015-10-18 04:24:36
【问题描述】:
我的错误
== 20150727183532 ActsAsTaggableOnMigration:迁移 ======================== -- create_table(:tags) 耙中止! StandardError:发生错误,此迁移和所有后续迁移已取消:
PG::DuplicateTable: 错误: 关系“标签”已经存在 : CREATE TABLE "tags" ("id" 序列主键,"name" 字符变化)
数据库中的第二次迁移:
create_table :tags do |t|
t.string :name
t.integer :taggings_count, default: 0
end
add_index :tags, :name, unique: true
create_table :taggings do |t|
t.references :tag
t.references :taggable, polymorphic: true
t.references :tagger, polymorphic: true
t.string :context, limit: 128
t.datetime :created_at
end
add_index :taggings, [ :tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type ],
unique: true, name: 'taggings_idx'
end
这是后来的迁移,问题似乎来自哪里?
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
Limit is created to prevent MySQL error on index
# length for MyISAM table type: http://bit.ly/vgW2Ql
t.string :context, limit: 128
t.datetime :created_at
end
add_index :taggings, :tag_id
add_index :taggings, [:taggable_id, :taggable_type, :context]
结束
def self.down drop_table :标记 drop_table :标签 结束
我试图了解进行此迁移的人打算做什么。
【问题讨论】:
标签: ruby-on-rails migration database-migration rails-migrations