微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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' }

原文地址:https://www.jb51.cc/ruby/273037.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐