【发布时间】: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