How to setup a Postgres extension?

前端 未结 1 1406
栀梦
栀梦 2021-01-03 02:41

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

1条回答
  •  爱一瞬间的悲伤
    2021-01-03 02:54

    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.

    0 讨论(0)
提交回复
热议问题