[Django]-How to execute the interactive commands programmatically in django-tenants

1👍

I solved my problem by running it in a periodic task instead of running manual rebuild index commands everytime. See code below…

from django.core import management

def hi():
     management.call_command('rebuild_index',schema_name="xxx",interactive=False)

2👍

You need to pass the schema name as a keyword argument called schema_name so that the tenant_command does not prompt. You also do not need to pass python manage.py.

The syntax you want is:

from django.core import management

management.call_command('tenant_command', 'rebuild_index', schema_name='xxx')

1👍

The function call_command only needs the command name, like this:

management.call_command('tenant_command', 'rebuild_index')

Try that and see if that works. Read the docs I linked as well, there are a few examples.

👤Ralf

Leave a comment