Reputation: 1776
I created a table and added an index to it. On a second migration I renamed the table. Will the index keep on working?
Upvotes: 19
Views: 6252
Reputation: 18037
No, you'll need to take care of the indexes yourself since the index is based on the table name. For example:
remove_index :old_table_name, :column_name
rename_table :old_table_name, :new_table_name
add_index :new_table_name, :column_name
From the Rails 4 upgrade guide:
In Rails 4.0 when a column or a table is renamed the related indexes are also renamed. If you have migrations which rename the indexes, they are no longer needed.
Upvotes: 36