ruby-on-rails – 使用index:true命名迁移中的索引

我有一个迁移,在下面,我用index:true创建索引.但是,该索引的名称太长,所以我试图自己命名.但是,这似乎没有运行.我得到相同的“名字太长”错误.有没有办法用index:true命名这样的索引?如果没有,我如何用add_index命名它?
class CreateVehicleProductApplicationNotes < ActiveRecord::Migration
  def change
    create_table :vehicle_product_application_notes do |t|
      t.references :product_id,index: true
      t.references :product_application_id,index: true,:name "my_index"
      t.references :note_id,index: true

      t.timestamps
    end
  end
end

解决方法

您可以传递包含索引名称的Hash,而不是true,如下所示,
t.references :product_application_id,index: { name: "my_index" }

参考:
http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html

相关文章

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