Ala*_*ain 5 postgresql ruby-on-rails hstore
首先,这可能看起来像是重复:
但事实并非如此.虽然我在这种情况下收到相同的错误消息.在检查数据库中是否安装了hstore时,我们可以看到它是:
./psql -d photographerio_development -c '\dx'
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+--------------------------------------------------
hstore | 1.2 | hstore | data type for storing sets of (key, value) pairs
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
Run Code Online (Sandbox Code Playgroud)
它也在template_1 DB上.
因此,当我尝试运行迁移以添加hstore时,我得到了PG::Error: ERROR: extension "hstore" already exists
,当我注释掉这个迁移时,在下一个需要hstore的情况下,它说PG::UndefinedObject: ERROR: type "hstore" does not exist
这有点悖论.
它是一个带有postgresql 9的Rails 4.0.1应用程序,我让hstore处理在这台机器上运行的其他一些项目.
Cra*_*ger 12
您已在hstore
名为的模式中安装了扩展,该模式hstore
可能不是您的默认模式search_path
.
您必须执行以下操作之一:
hstore
到search_path
连接在安装过程中;hstore
到search_path
带有ALTER USER ... SET
或ALTER DATABASE ... SET
;hstore
架构移动到public
; 要么hstore
,例如hstore.hstore(...)
.这也必须为运营商做; ->
变OPERATOR(hstore.->)
这就是我解决问题的方法。创建一个名为 Extensions 的架构,并向您在项目中使用的数据库用户名授予授权。
psql -U postgres -d template1 -c "CREATE SCHEMA extensions AUTHORIZATION <yourDbUserName>;"
Run Code Online (Sandbox Code Playgroud)
在创建的模式中创建扩展(扩展)
psql -U postgres -d template1 -c "CREATE EXTENSION IF NOT EXISTS hstore SCHEMA extensions;"
Run Code Online (Sandbox Code Playgroud)