Rails索引:在迁移中添加:btree索引类型

3

我正在尝试弄清如何运行一个迁移,以向索引添加B-Tree索引类型。

我尝试运行rails g migration add_index_to_recipes,这将给我创建一个空的迁移文件:

class AddIndexToRecipes < ActiveRecord::Migration[5.0]
  def change
  end
end

接着我这样修改了迁移:

class AddIndexToRecipes < ActiveRecord::Migration[5.0]
  def change
    add_column :recipes, :user_id, :integer
    add_index :recipes, :user_id, using: :btree
  end
end

然后我运行了rails db:migrate,但模式中仍然没有索引类型。 迁移成功运行,但我的模式仍然是这样的:

create_table "recipes", force: :cascade do |t|
    t.string "name"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer "user_id"
    t.index ["user_id"], name: "index_recipes_on_user_id"
  end

我希望它看起来像这样:

create_table "recipes", force: :cascade do |t|
    t.string "name"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer "user_id"
    t.index ["user_id"], name: "index_recipes_on_user_id", using: :btree
  end

这里曾经有类似的问题,但到目前为止我还没有想出解决办法。

我错过了什么吗?


谢谢。我在链接中没有找到任何有用的东西。也许我错过了什么?我没有收到任何错误...只是在我的模式中没有看到“using: :btree”。 - Belder
1个回答

2

我相信你已经明白了,但是对于其他找到这里的人来说,由于冗余,此内容似乎已从模式生成中删除 - https://github.com/rails/rails/pull/27981

希望这可以帮助到你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接