[Django]-How can I perform Django's `syncdb –noinput` with call_command?

44👍

call_command('syncdb', interactive = False)

EDIT:

I found the answer in the source code. The source code for all management commands can be found in a python module called management/commands/(command_name).py

The python module where the syncdb command resides is django.core.management.commands.syncdb

To find the source code of the command you can do something like this:

(env)$ ./manage.py shell
>>> from django.core.management.commands import syncdb
>>> syncdb.__file__
'/home/user/env/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.pyc'
>>> 

Of course, check the contents of syncdb.py, and not syncdb.pyc.

Or looking at the online source, the syncdb.py script contains:

    make_option('--noinput', action='store_false', dest='interactive', default=True,
        help='Tells Django to NOT prompt the user for input of any kind.'),

that tells us that instead of --noinput on the command line, we should use interactive if we want to automate commands with the call_command function.

Leave a comment