如何设置Postgres扩展? [英] How to setup a Postgres extension?

查看:142
本文介绍了如何设置Postgres扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最新版本的Django(1.8)中,添加了几个模型字段来利用Postgres数据类型。我对 HStoreField 感兴趣,文档要求设置一个PG 扩展程序,以便使用新的

如何实际使用这个 HStoreExtension 类执行数据库扩展?

解决方案

HStoreField docs ask您可以通过添加迁移来设置扩展。



您可以使用命令

创建一个空迁移

  ./ manage.py makemigrations yourapp --empty 

在创建迁移文件,然后可以导入扩展名

  django.contrib.postgres.operations import HStoreExtension 

并将其添加到操作列表中。

  operations = [
HStoreExtension(),
]

创建此迁移后,您可以使用您的模型中的HStoreField



举个例子,请参考 HStoreExtension()和 UnaccentExtension


In the latest release of Django (1.8), a few model fields have been added to take advantage of the Postgres data types. I am interested in HStoreField and the documentation asks to setup a PG extension in order to use the new HStoreFields in the models.

How do I actually use this HStoreExtension class to perform the database extension?

解决方案

The HStoreField docs ask you to set up the extension by adding a migration.

You can create an empty migration with the command

./manage.py makemigrations yourapp --empty

In the created migration file, you can then import the extension,

django.contrib.postgres.operations import HStoreExtension

and add it to the list of operations.

operations = [
    HStoreExtension(),
]

Once you have created this migration, you can then use the HStoreField in your models.

As an example, refer to this migration file used in the Django's postgres tests. It sets up two extensions, HStoreExtension() and UnaccentExtension.

这篇关于如何设置Postgres扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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