Alberto Peña Abril

Custom indices in Ruby on Rails migrations when using references

Ruby on Rails

Ruby on Rails uses references method creates the column in the table, and it also creates an index for the column by default.

The way to customise the index name is:

create_table :another_super_long_table_name do |t|
  t.references :super_long_table_name, index: { name: 'another_index' }
end

You can also explicitly tell Rails that you don’t want an index:

create_table :another_super_long_table_name do |t|
  t.references :super_long_table_name, index: false
end