Search code examples
pythondjangopostgresqlschemamulti-tenant

django-tenants TypeError: argument of type 'TenantQueryset' is not iterable


i've made a system for hotels , i want to give it to several hotels with the same base code , i have used django-tenant-schemas and this is my SHARED_APP and TENANT_APP but when i try python manage.py migrate_schemas --shared it only creates my shared apps list and when i try either manage.py migrate_schemas --tenant or manage.py migrate_schemas it raise this error

if public_schema_name in tenants: TypeError: argument of type 'TenantQueryset' is not iterable

this is my settings.py

SHARED_APPS = [
    'tenant_schemas',
    'users',
    'rosetta',
    'widget_tweaks',
    'import_export',

    'django.contrib.contenttypes',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

TENANT_APPS = [
    'rooms',
    'vistors',
    'booking',
    'costs',
    'payments',
    'cancel',
]

INSTALLED_APPS = list(SHARED_APPS) + [app for app in TENANT_APPS if app not in SHARED_APPS]
TENANT_MODEL= "rooms.Hotel"

#db engine 
'ENGINE': 'tenant_schemas.postgresql_backend',

my models.py

class Hotel(TenantMixin):
    hotel_name = models.CharField(max_length=40,unique=True)
    def __str__(self):
        return self.hotel_name

class Room(models.Model):
    room_no = models.IntegerField()
    #others 

and i have more models but all of them inherited from models.Model ,in the public schema it only created tables for SHARED_APP apps , TENANT_APP not created django version 2.2 db : postgresql is there something else i have to change or is'nt there another way to achieve that please


Solution

  • You haven't setup django tenant properly These are some few corrections

    1. From the settings.py file there should be only the shared and tenant app... And the installed app consist of the shared and tenant app
    2. Your tenant apps doesn't have some important apps like the content types ...

    There should be other errors, so I think you should go through these:

    1. Just checked your settings.py. You can follow this video ( https://youtu.be/QU70PbJuAUo )
    2. Your tenant apps lacks some vital apps which you can reference here https://github.com/Academy-Omen/saasy-blog

    Also make sure you can successfully connect your project to a PostgresSQL database before setting up django tenant.