安装 contrib 包后 pg_search dmetaphone 不起作用

Bab*_*z77 3 rubygems ruby-on-rails pg-search

安装 pq_search 并运行 contrib 包迁移后:

class InstallSomeContribPackages < ActiveRecord::Migration
  def up
    execute 'CREATE EXTENSION pg_trgm;'
    execute 'CREATE EXTENSION fuzzystrmatch;'
  end

  def down
    execute 'DROP EXTENSION pg_trgm;'
    execute 'DROP EXTENSION fuzzystrmatch;'
  end
end
Run Code Online (Sandbox Code Playgroud)

迁移 dmetaphone 迁移时仍然会抛出错误:

PG::UndefinedFunction: ERROR:  function dmetaphone(text) does not exist
LINE 2:   SELECT array_to_string(ARRAY(SELECT dmetaphone(unnest(rege...
Run Code Online (Sandbox Code Playgroud)

Bab*_*z77 5

我为其他在这个问题上挣扎的人发布了这个问题......

即使使用 contrib 包,我仍然需要安装 Fuzzystrmatch 扩展。

尝试 rake db:setup 和 rake db:test:prepare

如果这不起作用,请运行它们:

在终端本地访问你的 psql 并创建扩展:

\psql
create extension fuzzystrmatch;
Run Code Online (Sandbox Code Playgroud)

在 heroku 上访问您的 psql db 并从终端创建扩展:

heroku pg:psql
create extension fuzzystrmatch;
Run Code Online (Sandbox Code Playgroud)

然后重新运行迁移。希望这有助于减轻其他人的压力。