この素晴らしいチュートリアルを使用して、django-hstore を使用しようとしました。South が管理する既存のアプリに 2 つのクラスを追加しました。
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
。
さて、チュートリアルは不完全なようでした。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 を使用しています。