I have the following migration
class LinkDoctorsAndSpecializations < ActiveRecord::Migration
def up
add_reference :doctors, :doctor_specialization, polymorphic: true, index: true
end
def down
remove_reference :doctors, :doctor_specialization, polymorphic: true
end
end
when i run rake db:migrate
i am getting the error
Index name 'index_doctors_on_doctor_specialization_type_and_doctor_specialization_id' on table 'doctors' is too long; the limit is 63 characters
so how can i specify the index name when using add_reference like the way we specify in add_index :table, :column, :name => 'index name'
This would actually work:
Take a look for more examples.
I've heard the best way to fix this is to just leave it out of the add reference line and specify it manually below much like in the last line of your question
As I commented, do :
Here is documentation. Or, you can try this :
I would not suggest leaving out "add_reference", but you could leave out the "index" option hash key and then use "add_index":
Or, the more appropriate way would be like this: