ruby-on-rails – migrations:t.references不允许指定索引名称

迁移中有以下几个:
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

解决方法

根据 Rails code for references,您可以这样做,为索引提供一个Hash选项,您需要调用名称:name,so:
t.references :my_field,index: { name: 'my_index_name' }

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...