Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will removing a column with a Rails migration remove indexes associated with the column

In Rails 2, will removing a column with a Rails migration also change/remove indexes associated with the column? If not, and instead you have to also change/remove each index manually, shouldn't it instead be automated?

Thanks (from a Rails newbie)

like image 844
Dexygen Avatar asked Aug 26 '11 12:08

Dexygen


People also ask

What is index in rails migration?

An index is used to speed up the performance of queries on a database. Rails allows us to create index on a database column by means of a migration. By default, the sort order for the index is ascending. But consider the case where we are fetching reports from the database.

How do I remove a column from a table in Ruby on Rails?

remove_column :table_name, :column_name, :type Removes column, also adds column back if migration is rollbacked. Note: If you skip the data_type, the migration will remove the column successfully but if you rollback the migration it will throw an error.

Is Remove_index reversible?

Bookmark this question. Show activity on this post. And now I am trying to rollback but its showing error: StandardError: An error has occurred, this and all later migrations canceled: remove_index is only reversible if given a :column option.


2 Answers

From Rails 4 upwards, the index removes automatically with the column removal.

like image 65
enter08 Avatar answered Oct 04 '22 13:10

enter08


No, unfortunately you have to remove the index manually from within your migration using the remove_index method.

like image 31
John Topley Avatar answered Oct 04 '22 12:10

John Topley