Django basic operation commands

1. Create a new django project

django-admin.py startproject project-name

2. Create a new app

python manage.py startapp app-name

3. Synchronize the database

python manage.py makemigrations

python manage.py migrate

This method can create a table. When you add a new class to models.py, run it to automatically create a table in the database, without having to create it manually.

Note: To modify existing models, Django versions before Django 1.7 cannot automatically change the table structure, but there is a third-party tool south

4. Run the development server

python manage.py runserver 0.0.0.0:8000

5. Clear the database

python manage.py flush

This command will ask whether it is yes or no. Selecting yes will clear all the data, leaving only the empty table.

6. Create a super administrator

python manage.py createsuperuser

7. Export data, import data

python manage.py dumpdata appname > appname.json

python manage.py loaddata appname.json

8, django project environment terminal

python manage.py shell

If you install bpython or ipython, their interface will be called automatically

9. Database execution command

python manage.py dbshell

django will go to the database set in settings, if it is mysql or postgresql, it will ask for the username and password

You can enter sql statements in this terminal

10. More commands

Enter python manage.py on the terminal and press Enter, you can see a detailed list

 

Create cache table

python manage.py createcachetable

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263541&siteId=291194637