rails 给数据库表里加入索引

创建迁移文件

rails g migration add_product_images_index

编写迁移文件

db/migrate/20170119093958_add_product_images_index.rb

class AddProductImagesIndex < ActiveRecord::Migration[5.0]
  def change
    add_index :product_images, [:product_id, :weight] #创建联合索引
  end
end

执行迁移

rake db:migrate

posted @ 2021-07-20 07:53  HaimaBlog  阅读(97)  评论(0编辑  收藏  举报