我正在尝试弄清楚如何运行将 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
这里也有人问过类似的问题,但到目前为止我一直无法想出解决方案。
我错过了什么?
最佳答案
我相信您已经解决了这个问题,但对于其他在这里找到方法的人来说,这似乎是由于冗余而从架构生成中删除的 - https://github.com/rails/rails/pull/27981
希望这对您有所帮助。
关于ruby-on-rails - Rails 索引 : Adding :btree index type to migration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48345540/