Ruby on rails 使用索引命名迁移中的索引:true

Ruby on rails 使用索引命名迁移中的索引:true,ruby-on-rails,ruby,indexing,naming,Ruby On Rails,Ruby,Indexing,Naming,我在下面有一个migrate,在这里我创建了一个索引,索引为:true。但是,该名称对于该索引来说太长,因此我尝试自己命名它。然而,这似乎没有运行。我收到相同的“名称太长”错误。有没有办法用index:true来命名这样的索引?如果没有,我如何使用add_索引命名它 class CreateVehicleProductApplicationNotes < ActiveRecord::Migration def change create_table :vehicle_produ

我在下面有一个migrate,在这里我创建了一个索引,索引为:true。但是,该名称对于该索引来说太长,因此我尝试自己命名它。然而,这似乎没有运行。我收到相同的“名称太长”错误。有没有办法用index:true来命名这样的索引?如果没有,我如何使用add_索引命名它

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
class CreateVehicleProductApplicationNotes
您可以传递包含索引名称的哈希,而不是true,如下所示:

t.references :product_application_id, index: { name: "my_index" }
参考: