我有一个迁移:
class AddGinIndexToContacts < ActiveRecord::Migration
def up
execute("CREATE INDEX contacts_search_idx ON contacts USING gin (first_name gin_trgm_ops, last_name gin_trgm_ops, name gin_trgm_ops)")
end
def down
execute("DROP INDEX contacts_search_idx")
end
end
它在以下位置生成此代码schema.rb
:
add_index "contacts", ["first_name", "last_name", "name"], name: "contacts_search_idx", using: :gin
后来,当我执行rake db:schema:load
它时会生成错误的sql:
CREATE INDEX "contacts_search_idx" ON "contacts" USING gin ("first_name", "last_name", "name")
首先,它说:
错误:数据类型字符变化没有访问方法“gin”的默认运算符类
其次,有失gin_trgm_ops
。
如何使它起作用?
Rails 4.2