【问题标题】:Rails Indexing: Adding :btree index type to migrationRails 索引:将 :btree 索引类型添加到迁移
【发布时间】:2018-06-28 22:57:42
【问题描述】:

我试图弄清楚如何运行将 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

这里有人问过类似的问题,但到目前为止我一直无法提出解决方案。

我错过了什么?

【问题讨论】:

  • 您可以查看此链接:reddit.com/r/rails/comments/31rd8d/…
  • 谢谢。我没有在那个链接中找到任何有用的东西。也许我错过了什么?我没有收到任何错误...只是在我的架构中没有看到 using: :btree

标签: ruby-on-rails postgresql b-tree


【解决方案1】:

我相信您已经知道了这一点,但对于其他人在这里找到他们的方式,由于冗余,这似乎从模式生成中删除 - https://github.com/rails/rails/pull/27981

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2015-03-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 2019-10-22
    • 2018-06-15
    • 2013-05-03
    • 2021-09-06
    • 1970-01-01
    相关资源
    最近更新 更多