I have a migrate, below, where I create an index with index: true. However, the name is too long for that index so I attempted to name it myself. However, that doesn't seem to run. I get the same "name too long" error. Is there a way to name an index like this with index: true? If not, how do I go about naming it with 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
Instead of true, you can pass Hash containing name of the index as follows,
t.references :product_application_id, index: { name: "my_index" }
Reference: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With