Step one:
Open a terminal, enter the project path, enter django-admin startproject demo1 (your project name)
this is my project structure (input tree / F can view the structure.)
Step two:
Open the MySql service, and here I use Navicat is a client (Django default SQLite database, we can look at their own Baidu) into the settings.py in the configuration database,
And added import pymysql in _init_.py
pymysql.install_as_MySQLdb ()
The third step:
the input terminal enters demo01 directory under 01_sunk command python manage.py startapp myapp (your application name)
to activate the application in the settings.py INSTALLED_APPS below, FIG:
fourth step:
interact myall following definition model database models following
the new version of the foreign key relationship is defined when the primary plus on_delete = models.CASCADE
generated file migration run python manage.py makemigrations
given meaning module django. middle db.models no models this property
inspection found models.Model wrong model class Book (models.models) changed class Book (models.Model):
continue to run, ah ha actually was being given
a look at the causes are not id field should be set to run instead bid finally ok, tough Yeah
that's what I care deeply about the migration file, so good (this time is not yet generating a database table)
continue to run python manage.py migrate ah ha, ok operating results in the following figure into the database table View
Step five:
Test data;
running python manage.py shell into the python terminal
introduced packages
tested using, First we check the data class name .obejects.all ()
to test two bars, gain and find
Login.objects.all ( )
The result is an empty array, it is because I did not list things, all the results are empty
so we add a piece of data
to create a model class instance to create a Login object
the Login = Login ()
login.name = "tom"
login.password = "123456"
login.save ()
well, it's that a few steps, the code much, you can go to build a django environment pycharm above
one step ha ha ha ha