Skip to main content

Multi-tenancy on Django using PostgreSQL schemas.

Project description

Packaging: poetry Code style: black Build status Documentation status Code coverage PyPi version Downloads

This app uses PostgreSQL schemas to support data multi-tenancy in a single Django project. It is a fork of django-tenants with some conceptual changes:

  • There are static tenants and dynamic tenants. Static tenants can have their own apps and urlconf.

  • Tenants can be simultaneously routed via subdomain and via subfolder on shared subdomain.

  • Public is no longer the schema for storing the main site data. Public should be used only for true shared data across all tenants. Table “overriding” via search path is no longer encouraged.

  • Management commands can be run on multiple schemas via wildcards - the multiproc behavior of migrations was extended to just any tenant command.

Which package to use?

There are currently multiple packages to handle multi-tenancy via PostgreSQL schemas. This table should help you make an informed decision on which one to choose.




Original project.


Built on top of django-tenant-schemas. Uses a Domain model for allowing multiple domains per tenant. Allows for parallel migrations with custom migration executor. Other multiple improvements.


Built on top of django-tenants. Different philosphy for tenants. Other improvements listed above.


Breaking changes


  • [INTERNAL] Now storing active schema in asgiref.local instead of the connection object.


  • Dropped support for Python < 3.8, Django < 3.1.


  • Changed public API for getting/setting active schema. Public API is now get_current_schema, activate(schema), activate_public(). Any schema descriptor can still be used as context manager.

  • Changed location of tenant model and domain model in settings. TENANT_MODEL and DOMAIN_MODEL keys are now under TENANTS["default"] instead of TENANTS["public"]. This is required for future static-tenant-only configurations.

  • Module cache renamed to contrib.cache.

  • Module contrib.channels renamed to contrib.channels2.

  • Added module contrib.channels3.

  • Management command option --executor {sequential, parallel} renamed to --parallel.

  • All signals renamed. Added schema_activate signal.


  • Join the discussion at

  • PRs are welcome! If you have questions or comments, please use the link above.

  • To run the test suite run make or make coverage. The tests for this project live inside a small django project called dpgs_sandbox. Database password and database host can be set through the environment variables DATABASE_PASSWORD and DATABASE_HOST.


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_pgschemas-0.11.0.tar.gz (36.1 kB view hashes)

Uploaded source

Built Distribution

django_pgschemas-0.11.0-py3-none-any.whl (47.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page