Rails Migration: indexes on a renamed table

别说谁变了你拦得住时间么 提交于 2019-12-01 03:13:55

Rails 3

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

Rails 4+

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!