Rails Migration: indexes on a renamed table

▼魔方 西西 提交于 2019-11-30 22:35:58

问题


I created a table and added an index to it. On a second migration I renamed the table. Will the index keep on working?


回答1:


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.



来源:https://stackoverflow.com/questions/18701173/rails-migration-indexes-on-a-renamed-table

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