微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 使用index:true命名迁移中的索引

我有一个迁移,在下面,我用index:true创建索引.但是,该索引的名称太长,所以我试图自己命名.但是,这似乎没有运行.我得到相同的“名字太长”错误.有没有办法用index:true命名这样的索引?如果没有,我如何用add_index命名它?
class CreateVehicleProductApplicationNotes < ActiveRecord::Migration
  def change
    create_table :vehicle_product_application_notes do |t|
      t.references :product_id,index: true
      t.references :product_application_id,index: true,:name "my_index"
      t.references :note_id,index: true

      t.timestamps
    end
  end
end

解决方法

您可以传递包含索引名称的Hash,而不是true,如下所示,
t.references :product_application_id,index: { name: "my_index" }

参考:
http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐