Welcome to Django Multi-tenant’s documentation!
Python/Django support for distributed multi-tenant databases like Postgres+Citus
Enables easy scale-out by adding the tenant context to your queries, enabling the database (e.g. Citus) to efficiently route queries to the right database node.
There are architecures for building multi-tenant databases viz. Create one database per tenant, Create one schema per tenant and Have all tenants share the same table(s). This library is based on the 3rd design i.e Have all tenants share the same table(s), it assumes that all the tenant relates models/tables have a tenant_id column for representing a tenant.
The following link talks more about the trade-offs on when and how to choose the right architecture for your multi-tenat database:
- Supported Django and Citus versions/Pre-requisites
- Supported APIs
- Migrating a multi-tenant Django application to Citus
- Preparing to scale-out a multi-tenant application
- 1. Introducing the tenant column to models belonging to an account
- 2. Include the account_id in all primary keys and unique constraints
- 3. Updating the models to use TenantModel and TenantForeignKey
- 4. Distribute data in Citus
- Updating the Django Application to scope queries
- Automating with middleware