我尝试使用这个很好的教程使用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()
Run Code Online (Sandbox Code Playgroud)
做了一个schemamigration --auto,启动了迁移并得到了一个django.db.utils.DatabaseError: type "hstore" does not exist.
好吧,tuto似乎不完整,django-hstore 文档告诉我使用自定义数据库后端,我将以下内容添加到我的设置文件中:
DATABASES['default']['ENGINE'] = 'django_hstore.postgresql_psycopg2'
Run Code Online (Sandbox Code Playgroud)
后来我有一个KeyError: 'default'在south/db/__init__.py", line 78.此时,intertubes +一些试验/错误将我指向SOUTH_DATABASE_ADAPTERS设置变量,我在设置中添加了以下内容:
SOUTH_DATABASE_ADAPTERS = {'default': 'south.db.postgresql_psycopg2'}
Run Code Online (Sandbox Code Playgroud)
新错误:
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. …Run Code Online (Sandbox Code Playgroud)