My project is in early development. I frequently delete the database and run manage.py syncdb
to set up my app from scratch.
Unfortunately, this always pops up:
You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no):
Then you have supply a username, valid email adress and password. This is tedious. I'm getting tired of typing test\[email protected]\ntest\ntest\n
.
How can I automatically skip this step and create a user programatically when running manage.py syncdb
?
Django's “Hello World” application Start the terminal by clicking on the “Run” button. Type python3 manage.py createsuperuser in the given terminal and press “Enter”. The system will ask for credentials, after which a superuser will be created. To run the server, we type the command python3 manage.py runserver 0.0.
Django-admin.py: It is a Django's command line utility for administrative tasks. Manage.py: It is an automatically created file in each Django project. It is a thin wrapper around the Django-admin.py.
syncdb is a command which is executed in django shell to create tables for first time for apps which are added to INSTALLED_APPS of settings.py.
The startproject will create the main project directory, while the startapp will create the app directory. Both are also been passed a name to be used in generation. The startproject is the first command run when creating a new project, while the startapp is run inside the new project directory.
I know the question has been answered already but ...
A Much simpler approach is to dump the auth module data into a json file once the superuser has been created:
./manage.py dumpdata --indent=2 auth > initial_data.json
You can also dump the sessions data:
./manage.py dumpdata --indent=2 sessions
You can then append the session info to the auth module dump (and probably increase the expire_date so it does not expire... ever ;-).
From then, you can use
/manage.py syncdb --noinput
to load the superuser and his session when creating the db with no interactive prompt asking you about a superuser.
Instead of deleting your entire database, just delete the tables of your app before running the syncdb
This will accomplish it for you in a single line (per app):
python manage.py sqlclear appname | python manage.py dbshell
The first command will look at your app and generate the required SQL to drop the tables. This output is then piped to the dbshell to execute it.
After its done, run your syncdb to recreate the tables:
python manage.py syncdb
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