I am reading a book ("Learning Django Web Development" by Sanjeev Jaiswal and Ratan Kumar) on Django, but the book is based on an earlier version of Django (prior to version 1.9). In order to populate the database with tables, the book uses the syncdb command:
$ python manage.py syncdb
Then the book says that terminal will prompt you to create a superuser account.
the syncdb command is no longer used in Django version 1.9 and up. After some research, it seems as if the migrate command populates the databse with tables, but it does not prompt the creation of a superuser account. How can I do this in Django 1.9.6?
First we’ll need to create a user who can login to the admin site. Run the following command:
Enter your desired username and press enter. Username: admin
You will then be prompted for your desired email address:
The final step is to enter your password. You will be asked to enter your password twice, the second time as a confirmation of the first.
first run
in cmd prompt,then apply migration by
mysite:
then
after that
I think you want to run these commands:
python manage.py makemigrations
creates migration files based on your modelspython manage.py migrate
will create the tables in your db based on the migration files created(see docs for more details on database migrations)
python manage.py createsuperuser
will create a superuser for your application in the database (docs)For Django 2
From the docs
Which can be embedded in a script, called from a command line or triggered via an API
https://docs.djangoproject.com/en/1.9/ref/django-admin/
$ python manage.py createsuperuser
It will ask username and password
http://127.0.0.1:8000/admin/ see
https://www.tutorialshore.com/create-new-admin-user-in-django/