我在迁移中有以下内容:
create_table :model_with_a_long_name do |t|
t.references :other_model_with_an_equally_long_name, index: true
end
这会产生一个 Postgres 名称太长的索引。
有没有办法手动指定索引名称(无需单独添加整数列和索引)?
像下面这样:
create_table :model_with_a_long_name do |t|
t.references :other_model_with_an_equally_long_name, index: true, index_name: 'model_and_other'
end
?
根据轨道代码references https://github.com/rails/rails/blob/8e4ab75aa21cc482fc7e9c2c269ac37a40340dfa/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L351,你可以这样做,提供index
a Hash
带有选项,您需要调用的选项:name
, so:
t.references :my_field, index: { name: 'my_index_name' }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)