Name the index in Migrate with index: true

I have a migration below where I create an index with an index: true. However, this name is too long for this index, so I tried to name it myself. However, this does not seem to work. I get the same "too long" error. Is there a way to name an index like this with the index: true? If not, how can I name it using 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 
+6
source share
1 answer

Instead of true, you can pass a Hash containing the index name as follows:

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

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

+7
source

Source: https://habr.com/ru/post/976837/


All Articles