如何使用南方管理的现有应用程序设置django-hstore? [英] How to setup django-hstore with an existing app managed by south?

查看:176
本文介绍了如何使用南方管理的现有应用程序设置django-hstore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用这个漂亮的教程使用django-hstore。我为由South管理的现有应用程序添加了两个类:

I tried to use django-hstore using this nice tutorial. I added two classes to an existing app managed by 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:键入hstore不存在

made a schemamigration --auto, launched the migration and got a django.db.utils.DatabaseError: type "hstore" does not exist.

好的,tuto似乎不完整,django-hstore 文档告诉我要使用自定义数据库后端,我将以下内容添加到我的设置文件中:

Okay, the tuto seemed to be incomplete, the django-hstore documentation told me to use the custom database backend, i added the following to my settings file:

DATABASES['default']['ENGINE'] = 'django_hstore.postgresql_psycopg2'

然后我在 south / db / __ init__.py,第78行中得到一个 KeyError:'default'。在这一点上,Intertubes +一些试用/错误指向我的 SOUTH_DATABASE_ADAPTERS 设置变量,并在设置中添加了以下内容:

Then I got a KeyError: 'default' in south/db/__init__.py", line 78. At this point, the intertubes + some trial/errors pointed me to the SOUTH_DATABASE_ADAPTERS settings variable and I added the following to the settings:

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 extension:

Now this is odd because I installed the hstore extension :

$ 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。

How is this supposed to work ? I'm using Django 1.4, Postgresql 9.1.

推荐答案

我最终发现没有为特定数据库安装hstore扩展我正在使用:

I eventually found that the hstore extension wasn't installed for the specific database I was using:

$ psql -d mydb
psql (9.1.4)
Type "help" for help.

mydb=# SELECT t.oid, typarray FROM pg_type t JOIN pg_namespace ns ON typnamespace = ns.oid WHERE typname = 'hstore';
 oid | typarray 
-----+----------
(0 rows)

mydb=# \dx
                 List of installed extensions
  Name   | Version |   Schema   |         Description          
---------+---------+------------+------------------------------
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
(1 row)

mydb=# create extension hstore;
WARNING:  => is deprecated as an operator name
DETAIL:  This name may be disallowed altogether in future versions of PostgreSQL.
CREATE EXTENSION
mydb=# \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)

mydb=# SELECT t.oid, typarray FROM pg_type t JOIN pg_namespace ns ON typnamespace = ns.oid WHERE typname = 'hstore';
  oid  | typarray 
-------+----------
 58800 |    58805
(1 row)

我以为在安装hstore之后创建的数据库将包括扩展。似乎不是这样,我是否误解了扩展程序的工作原理?数据库是否具体?

I thought that a database created after the hstore installation would include the extension. Doesn't seem to be the case, am I misinterpreting how extensions work ? Are they database-specific ?

这篇关于如何使用南方管理的现有应用程序设置django-hstore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆