Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在Heroku Postgres数据库上启用contrib模块_Ruby On Rails_Postgresql_Heroku - Fatal编程技术网

Ruby on rails 如何在Heroku Postgres数据库上启用contrib模块

Ruby on rails 如何在Heroku Postgres数据库上启用contrib模块,ruby-on-rails,postgresql,heroku,Ruby On Rails,Postgresql,Heroku,我试图在Heroku上新的Postgres 9共享数据库中使用contrib模块。更具体地说,pg_trgm和fuzzystrmatch模块。上面说 此外,还提供了许多免费扩展,如 fuzzystrmatch、pg_trgm和uncent 我似乎找不到任何关于如何在共享Heroku数据库上实际启用这些模块的文档。见下面的答案 注意: 我尝试通过使用连接到数据库来添加它们 heroku pg:psql HEROKU_POSTGRESQL_BROWN 跑步 create extension pg_

我试图在Heroku上新的Postgres 9共享数据库中使用contrib模块。更具体地说,pg_trgmfuzzystrmatch模块。上面说

此外,还提供了许多免费扩展,如 fuzzystrmatch、pg_trgm和uncent

我似乎找不到任何关于如何在共享Heroku数据库上实际启用这些模块的文档。见下面的答案

注意:

我尝试通过使用连接到数据库来添加它们

heroku pg:psql HEROKU_POSTGRESQL_BROWN
跑步

create extension pg_trgm
create extension fuzzystrmatch
但是在尝试使用它之后

SELECT levenshtein('tests', 'test');
它还说

ERROR:  function levenshtein(unknown, unknown) does not existLINE 1: SELECT levenshtein('tests', 'test');
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
有人知道为什么会发生这种情况吗?

在搜索堆栈溢出时找到了答案。我不知道为什么我的谷歌搜索中没有出现。如果有人用同样的措辞来搜索这个问题,我将把问题留在这里

要启用模块,您需要将其添加到迁移中,如下所示:

def up
  execute "create extension fuzzystrmatch"
  execute "create extension pg_trgm"
end

在较新版本的Rails中,只需执行以下操作即可:

def change
  enable_extension "fuzzystrmatch"
  enable_extension "pg_trgm"
end

如果需要编写
向上
向下
方法,则
启用扩展
的相应方法是
禁用扩展

注意:必须使用postgresql 9.1才能工作。要从旧版本升级,请执行以下操作:dev()、prod(),您可以通过
echo'show extwlist.extensions'| Heroku pg:psql