Because just use models To define a table is too much trouble
This article is mainly about mysql Create a table in and then directly in models Generate code in
step1:
stay mysql Create a table
step2:
stay cmd Input in python manage.py inspectdb>polls/models.py
among polls Created for you app name
step3:
Click on models.py That is, the generation is complete
Attached separately models The code written in maps to MySQL The method in
step1:
Enter the name of the table you want to create
class StudentInfo(models.Model):
stu_id = models.CharField(primary_key=True, max_length=20)
stu_name = models.CharField(max_length=20)
stu_psw = models.CharField(max_length=20)
step2:
cmd Input in python manage.py makemigrations polls
(polls For you app name )
The successful result is shown in the figure
step3:
cmd Input in python manage.py migrate
Refresh MySQL In the table
The addition is complete