最近我在尝试使用Djang与Django时遇到了麻烦.我用这种方式安装了hstore:
$ sudo -u postgres psql
postgres=# CREATE EXTENSION hstore;
WARNING: => is deprecated as an operator name
DETAIL: This name may be disallowed altogether in future versions of PostgreSQL.
CREATE EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+--------------------------------------------------
hstore | 1.0 | public | data type for storing sets of (key, value) pairs
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
Run Code Online (Sandbox Code Playgroud)
并天真地认为我的新数据库将包括hstore.情况并非如此:
$ createdb dbtest …Run Code Online (Sandbox Code Playgroud) 首先,这可能看起来像是重复:
但事实并非如此.虽然我在这种情况下收到相同的错误消息.在检查数据库中是否安装了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处理在这台机器上运行的其他一些项目.