Ruby on rails 由于索引名过长,Rails 5.2迁移失败
您好,我正在尝试进行迁移Ruby on rails 由于索引名过长,Rails 5.2迁移失败,ruby-on-rails,Ruby On Rails,您好,我正在尝试进行迁移rakedb:migration,以添加新表和新索引。 然而,我得到了这个错误: Caused by: ArgumentError: Index name 'index_cite_this_article_referencings_on_referencer_type_and_referencer_id' on table 'cite_this_article_referencings' is too long; the limit is 64 characters 这
rakedb:migration
,以添加新表和新索引。
然而,我得到了这个错误:
Caused by:
ArgumentError: Index name 'index_cite_this_article_referencings_on_referencer_type_and_referencer_id' on table 'cite_this_article_referencings' is too long; the limit is 64 characters
这是可以理解的,但是在我定义了索引的名称之后,迁移并没有使用我自己定义的索引名称,并且仍然给出相同的错误
以下是我的迁移:
class CreateCiteThisArticleReferencings < ActiveRecord::Migration[5.2]
def change
create_table :cite_this_article_referencings do |t|
t.belongs_to :article
t.belongs_to :referencer, polymorphic: true
t.timestamps
t.index [:article_id], name: "cite_this_article_referencings_a_id", unique: true
t.index [:referencer_id], name: "cite_this_article_referencings_r_id", unique: true
t.index [:referencer_id, :referencer_type], name: "cite_this_article_referencings_all_ids", unique: true
end
end
end
class-createCiteThisArticleReferences
迁移无法捕获引用这篇文章\u引用所有\u ID
;相反,它仍然使用自己创建的名称index\u cite\u this\u article\u references\u on\u referencer\u type\u和\u referencer\u id
轨道5.2.3;Ruby 2.5.1;马科斯·莫哈韦。
谢谢你的帮助 提供:name选项,例如:
这一点以前已经得到了回答@JasonBrodie你好,谢谢你的链接。属于的
很棘手。。。
add_index :cite_this_article_referencings,
[:referencer_id, :referencer_type],
:unique => true,
:name => 'my_index'