gpt4 book ai didi

ruby-on-rails - 使用 add_reference 时指定自定义索引名称

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

我有以下迁移

class LinkDoctorsAndSpecializations < ActiveRecord::Migration
def up
add_reference :doctors, :doctor_specialization, polymorphic: true, index: true
end

def down
remove_reference :doctors, :doctor_specialization, polymorphic: true
end
end

当我运行 rake db:migrate 时出现错误

表“doctors”上的索引名称“index_doctors_on_doctor_specialization_type_and_doctor_specialization_id”太长;限制为 63 个字符

那么在使用 add_reference 时如何指定索引名称,就像我们在 add_index :table, :column, :name => 'index name'

中指定的那样

最佳答案

作为我commented , 做:

add_index :table, :column, name: 'index name' 

这里是 documentation .或者,您可以试试这个:

class LinkDoctorsAndSpecializations < ActiveRecord::Migration
def change
add_reference :doctors, :doctor_specialization, polymorphic: true, index: { name: 'index name' }
end
end

关于ruby-on-rails - 使用 add_reference 时指定自定义索引名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30366315/

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