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)
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.
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.
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.
From Rails 4 upwards, the index removes automatically with the column removal.
No, unfortunately you have to remove the index manually from within your migration using the remove_index
method.
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