I'm trying to sync my db from a view, something like this:
from django import http
from django.core import management
def syncdb(request):
management.call_command('syncdb')
return http.HttpResponse('Database synced.')
The issue is, it will block the dev server by asking for user input from the terminal. How can I pass it the '--noinput'
option to prevent asking me anything?
I have other ways of marking users as super-user, so there's no need for the user input, but I really need to call syncdb
(and flush
) programmatically, without logging on to the server via ssh. Any help is appreciated.
The runserver command is a built-in subcommand of Django's manage.py file that will start up a development server for this specific Django project.
Django Inspectdb Refactor will automatically create the required folders and create separate python files for each model. You can install it via pip or to get the latest version clone this repo. Add ``inspectdb_refactor`` to your ``INSTALLED_APPS`` inside settings.py of your project. make models in that particular app.
Providing data with fixtures The most straightforward way of creating a fixture if you've already got some data is to use the manage.py dumpdata command. Or, you can write fixtures by hand; fixtures can be written as JSON, XML or YAML (with PyYAML installed) documents.
management.call_command('syncdb', interactive=False)
Works like this (at least with Django 1.1.):
from django.core.management.commands import syncdb
syncdb.Command().execute(noinput=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With