我尝试使用这个不错的教程来使用 django-hstore 。我在 South 管理的现有应用程序中添加了两个类:
class Attribute(models.Model):
name = models.CharField(max_length=200, verbose_name=_("name"))
description = models.CharField(max_length=1000, verbose_name=_("description"))
class Measure(models.Model):
attribute = models.ForeignKey(Attribute)
data = hstore.DictionaryField(db_index=True)
objects = hstore.HStoreManager()
做了一个schemamigration --auto
,启动了迁移,得到了一个django.db.utils.DatabaseError: type "hstore" does not exist
.
好的,tuto 似乎不完整,django-hstore文档告诉我使用自定义数据库后端,我在我的设置文件中添加了以下内容:
DATABASES['default']['ENGINE'] = 'django_hstore.postgresql_psycopg2'
然后我KeyError: 'default'
进去了south/db/__init__.py", line 78
。此时,intertubes + 一些试验/错误将我指向SOUTH_DATABASE_ADAPTERS
设置变量,我将以下内容添加到设置中:
SOUTH_DATABASE_ADAPTERS = {'default': 'south.db.postgresql_psycopg2'}
新错误:
File ".../psycopg2/extras.py", line 769, in register_hstore
"hstore type not found in the database. "
psycopg2.ProgrammingError: hstore type not found in the database. please install it from your 'contrib/hstore.sql' file
现在这很奇怪,因为我安装了 hstore 扩展:
$ sudo -u postgres psql
create extension hstore;
postgres=# CREATE EXTENSION hstore;
ERROR: extension "hstore" already exists
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)
postgres=# SELECT 'hstore'::regtype::oid;
oid
-------
57704
(1 row)
这应该如何工作?我正在使用 Django 1.4、Postgresql 9.1。