{"id":14532,"library":"django-postgres-extra","title":"django-postgres-extra","description":"django-postgres-extra brings advanced PostgreSQL features like HStore fields, partitioned models, and enhanced querying capabilities directly into Django's ORM. It seamlessly integrates with Django models and querysets, allowing developers to leverage PostgreSQL-specific functionality without writing raw SQL. The current stable version is 2.0.9, with a 3.0.0 release candidate recently published, indicating an active development and release cadence.","status":"active","version":"2.0.9","language":"en","source_language":"en","source_url":"https://github.com/SectorLabs/django-postgres-extra","tags":["django","postgresql","orm","database","hstore","partitioning"],"install":[{"cmd":"pip install django-postgres-extra","lang":"bash","label":"Install stable version"},{"cmd":"pip install django-postgres-extra==3.0.0rc1","lang":"bash","label":"Install release candidate (Django 5.2+)"}],"dependencies":[{"reason":"Core dependency for any Django-based library, supports Django >=3.2","package":"Django","optional":false}],"imports":[{"symbol":"HStoreField","correct":"from pg_extra.fields import HStoreField"},{"note":"Partitioned models moved under pg_extra.models for Django 3.0+","wrong":"from pg_extra.partitioned_models import PostgreSQLPartitionedModel","symbol":"PostgreSQLPartitionedModel","correct":"from pg_extra.models import PostgreSQLPartitionedModel"},{"symbol":"PostgreSQLQuerySet","correct":"from pg_extra.query import PostgreSQLQuerySet"}],"quickstart":{"code":"import os\nfrom django.conf import settings\nfrom django.db import models\n\n# Minimal Django setup (for demonstration only)\nif not settings.configured:\n    settings.configure(\n        INSTALLED_APPS=['pg_extra', __name__],\n        DATABASES={\n            'default': {\n                'ENGINE': 'django.db.backends.postgresql',\n                'NAME': os.environ.get('PG_DB_NAME', 'test_db'),\n                'USER': os.environ.get('PG_DB_USER', 'user'),\n                'PASSWORD': os.environ.get('PG_DB_PASSWORD', 'password'),\n                'HOST': os.environ.get('PG_DB_HOST', 'localhost'),\n                'PORT': os.environ.get('PG_DB_PORT', '5432')\n            }\n        },\n        DEFAULT_AUTO_FIELD='django.db.models.BigAutoField'\n    )\n\nfrom pg_extra.fields import HStoreField\n\nclass Product(models.Model):\n    name = models.CharField(max_length=255)\n    properties = HStoreField(blank=True, null=True, default=dict)\n\n    def __str__(self):\n        return self.name\n\n    class Meta:\n        app_label = 'my_app' # Required for this minimal setup\n\n# Example usage (requires a configured Django project and migrations applied)\n# print('Ensure pg_extra is in INSTALLED_APPS and run migrations.')\n# try:\n#     p = Product.objects.create(name='Smartphone', properties={'color': 'black', 'storage_gb': '128'})\n#     print(f\"Created product: {p.name} with properties {p.properties}\")\n#     retrieved_p = Product.objects.get(name='Smartphone')\n#     print(f\"Retrieved product color: {retrieved_p.properties['color']}\")\n# except Exception as e:\n#     print(f\"Error during quickstart: {e}\")","lang":"python","description":"To use `django-postgres-extra`, you must add 'pg_extra' to your `INSTALLED_APPS` in `settings.py`. This example demonstrates defining a model with an `HStoreField`, allowing flexible key-value storage. After adding the app and defining the model, run `python manage.py makemigrations` and `python manage.py migrate`."},"warnings":[{"fix":"Consult the official release notes and documentation for version 3.x upon its stable release. Test thoroughly before upgrading in production environments, particularly if leveraging partitioned models or custom primary keys.","message":"Version 3.0.0rc1 (and likely future 3.0.0 stable) introduces significant changes, including support for Django 5.2+ and Python 3.13, and integrates with Django 5.2's `CompositePrimaryKey` for partitioned models. Users upgrading from 2.x to 3.x, especially those using partitioned models, should review the changelog carefully for potential breaking changes in model definitions and behavior.","severity":"breaking","affected_versions":"3.0.0rc1+"},{"fix":"Upgrade to `django-postgres-extra` version `2.0.9` or newer. Alternatively, if upgrading is not immediately possible, manually create the `hstore` extension in your PostgreSQL database: `CREATE EXTENSION IF NOT EXISTS hstore;`.","message":"Automatic `hstore` extension creation was broken for Django 4.2 or newer in `django-postgres-extra` versions prior to `2.0.9rc11` (and thus prior to `2.0.9`). If you are on an older version of `django-postgres-extra` (e.g., 2.0.8 or earlier) and using Django 4.2+, you might encounter issues with HStoreField functionality.","severity":"gotcha","affected_versions":"<2.0.9"},{"fix":"Add `'pg_extra'` to your `INSTALLED_APPS` list in `settings.py`.","message":"Like most Django apps, `django-postgres-extra` must be added to your `INSTALLED_APPS` setting in `settings.py`. Failing to do so will prevent its features from being registered with Django and migrations from being generated or applied correctly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly read the `django-postgres-extra` documentation on partitioned models and PostgreSQL's native partitioning features. Plan your partitioning strategy carefully, test migrations extensively, and monitor performance after implementation.","message":"Utilizing advanced PostgreSQL features like partitioned models, especially with custom primary keys or complex partitioning strategies, adds complexity to your application's architecture. Schema changes, migrations, and ensuring data integrity require careful planning and understanding of PostgreSQL's partitioning mechanics.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[],"ecosystem":"pypi"}