Is it possible to create a django_tenant_superuser via management.call_command?

816 views Asked by At

I'm building a multi-tenant project with django-tenant.

The issue I'm encountering is that "password" is not a valid flag option.

    management.call_command(
        'create_tenant_superuser', 
        interactive = False,
        username = "user"
        password = "password"
        ) 

gives error:

TypeError: Unknown option(s) for create_tenant_superuser command: password Valid options are: ...
1

There are 1 answers

0
Abdul Aziz Barkat On BEST ANSWER

You can use the schema_context [django-tenants docs] context manager to make queries to specific schemas by providing the schema name:

from django.contrib.auth import get_user_model
from django_tenants.utils import schema_context


UserModel = get_user_model()

with schema_context(schema_name):
    UserModel.objects.create_superuser(username="user", password="password")