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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…