加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails Migration:重命名表上的索引

发布时间:2020-12-16 21:47:06 所属栏目:百科 来源:网络整理
导读:我创建了一个表并添加了一个索引. 在第二次迁移时,我重命名了表. 索引会继续工作吗? 解决方法 Rails 3 不,您需要自己处理索引,因为索引基于表名.例如: remove_index :old_table_name,:column_namerename_table :old_table_name,:new_table_nameadd_index :
我创建了一个表并添加了一个索引.
在第二次迁移时,我重命名了表.
索引会继续工作吗?

解决方法

Rails 3

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

remove_index :old_table_name,:column_name
rename_table :old_table_name,:new_table_name
add_index :new_table_name,:column_name

轨道4

从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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读