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

前端 未结 6 848
一个人的身影
一个人的身影 2021-01-07 15:46

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 ind

6条回答
  •  不思量自难忘°
    2021-01-07 16:51

    Just as a caution, while Rails 4 will remove the index for you if you remove the column, you should specify the column type. Without a column type, running rake db:rollback will return

    rake aborted!
    StandardError: An error has occurred, all later migrations canceled:
    
    remove_column is only reversible if given a type.
    

    I was experimenting with dropping foreign key columns that were indexed. Even specifying index: true in the change block didn't seem to make the columns reversible on rollback.

提交回复
热议问题