{"id":23584,"library":"django-multitenant","title":"django-multitenant","description":"Django library to implement multi-tenant databases, primarily targeting Citus (PostgreSQL extension for horizontal scaling). Supports Django 3.2 to 5.0 with Python 3.8+. Provides mixins, managers, and utilities to isolate tenant data via a tenant_id column. Release cadence is irregular, with the latest stable version 4.1.1 from 2024.","status":"active","version":"4.1.1","language":"python","source_language":"en","source_url":"https://github.com/citusdata/django-multitenant","tags":["django","multitenant","citus","postgresql","saas"],"install":[{"cmd":"pip install django-multitenant","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core dependency, supports 3.2+","package":"Django","optional":false}],"imports":[{"note":"Mixin was moved to mixins module in v3.0.0","wrong":"from django_multitenant.models import TenantModelMixin","symbol":"TenantModelMixin","correct":"from django_multitenant.mixins import TenantModelMixin"},{"note":"","symbol":"TenantManager","correct":"from django_multitenant.managers import TenantManager"}],"quickstart":{"code":"import os\nfrom django.db import models\nfrom django_multitenant.mixins import TenantModelMixin\nfrom django_multitenant.models import TenantModel\n\nclass Tenant(models.Model):\n    tenant_id = models.AutoField(primary_key=True)\n    name = models.CharField(max_length=100)\n\nclass Project(TenantModelMixin, models.Model):\n    tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE)\n    name = models.CharField(max_length=100)\n\n    class Meta:\n        app_label = 'myapp'\n\n# In your settings, ensure DATABASES and MIDDLEWARE are configured\n# See https://django-multitenant.readthedocs.io/","lang":"python","description":"Define a Tenant model and a tenant-aware model using TenantModelMixin."},"warnings":[{"fix":"Change import to from django_multitenant.mixins import TenantModelMixin","message":"In v3.0.0, TenantModelMixin was moved from django_multitenant.models to django_multitenant.mixins. Old imports will break.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"class MyModel(TenantModelMixin, models.Model): ...","message":"TenantModelMixin must be listed before models.Model in the class definition to avoid MRO issues.","severity":"gotcha","affected_versions":"all"},{"fix":"Explicitly define a through model with a ForeignKey to the tenant model.","message":"When using ManyToMany fields between tenant models, the intermediate table may not include the tenant column automatically. You must define a through model with tenant_id.","severity":"gotcha","affected_versions":"all"},{"fix":"Use TenantModelMixin with models.Model instead of inheriting TenantModel.","message":"The TenantModel base class is deprecated in favor of TenantModelMixin + models.Model.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change import to: from django_multitenant.mixins import TenantModelMixin","cause":"TenantModelMixin was moved to django_multitenant.mixins in v3.0.0.","error":"AttributeError: module 'django_multitenant.models' has no attribute 'TenantModelMixin'"},{"fix":"Add a ForeignKey field to the Tenant model on your tenant-aware models: tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE)","cause":"The model uses TenantModelMixin but does not have a ForeignKey to the Tenant model, or the tenant field is missing.","error":"django.db.utils.ProgrammingError: column \"tenant_id\" of relation \"myapp_project\" does not exist"},{"fix":"In your view or middleware, call: from django_multitenant.utils import set_current_tenant; set_current_tenant(tenant_instance)","cause":"The middleware or code did not set the current tenant via set_current_tenant() before a query.","error":"AssertionError: Tenant id is not set"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}