ruby-on-rails - Rails 索引 : Adding :btree index type to migration

标签 ruby-on-rails postgresql b-tree

我正在尝试弄清楚如何运行将 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/

相关文章:

mysql - Rails 应用程序已部署并正常运行,但 MySQL 数据库显示为空

postgresql - 如何找到特定操作系统数据文件关联的 postgres 表?

sql - 选择 postgreSQL 中可用的最准确的数据?

java - 无法使用 Jooq 执行 PostgreSQL 函数

ruby-on-rails - WebSocket 连接到 'ws://localhost:35729/livereload' 失败:连接建立错误:net::ERR_CONNECTION_REFUSED

javascript - Rails 3.2 Dev 环境 sourceMaps 支持 JavaScript

database - Berkeley DB java 版本,Java 中的任何 LGPL 或 BSD 替代品?

concurrency - POSIX 的 read() 和 write() 系统调用是原子的吗?

algorithm - 范围最小查询、动态数组、区间树、treap

ruby-on-rails - 获取 OCIError : ORA-00932: inconsistent datatypes From Rails 3