Rails迁移:重命名表上的索引 [英] Rails Migration: indexes on a renamed table

查看:152
本文介绍了Rails迁移:重命名表上的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表并为其添加了索引。
在第二次迁移中,我重命名了该表。
指数会继续工作吗?

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

推荐答案

Rails 3



不,您需要自己处理索引,因为索引基于表名。例如:

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 +



来自 Rails 4升级指南


在Rails 4.0中,当重命名列或表时,也会重命名相关索引。如果您有重命名索引的迁移,则不再需要它们。

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.

这篇关于Rails迁移:重命名表上的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆