Rails的ActiveRecord的::移民什么是指数之间的区别:真和add_index? [英] Rails ActiveRecord::Migration what is the difference between index: true and add_index?

查看:130
本文介绍了Rails的ActiveRecord的::移民什么是指数之间的区别:真和add_index?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间的区别是什么

  t.boolean:is_live,索引:真
 

  add_index:table_name的,:is_live
 

如果没有区别,为什么只有 add_index 体现在schema.rb。当我使用指数:真正的,我不能真正看到指数 schema.rb 。我应该只使用 add_index 方法。

在使用 add_index 的方法,我可以看到在我的schema.rb

  add_index表格名,[is_live],名称:index_table_name_on_is_live,使用::blahblah
 

解决方案

简而言之:无论做同样的工作。指数:真'只是保存您的附加导线。看看这里<一href="https://github.com/rails/rails/pull/5262#issuecomment-4329571">https://github.com/rails/rails/pull/5262#issuecomment-4329571

What is the difference between

t.boolean :is_live, index: true

and

add_index :table_name, :is_live

If there is no difference, how come only the add_index is reflected in schema.rb. When I use index: true, I can't actually see the index in schema.rb. Should I only use the add_index method.

When use the add_index method, I can see this in my schema.rb

add_index "table_name", ["is_live"], name: "index_table_name_on_is_live", using: :blahblah

解决方案

In short: both do the same job. ìndex: true` just saves you an additional line. Look here https://github.com/rails/rails/pull/5262#issuecomment-4329571

这篇关于Rails的ActiveRecord的::移民什么是指数之间的区别:真和add_index?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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