On the basis of the first three summaries, a stu application app is recreated here, and the models module is analyzed and the code is organized
content
- Creation of stu
- Configuration of models in stu
- data migration
- perform migration
Creation of stu
For the detailed method, see the creation of myapp in the previous article. It is exactly the same as myapp, but it is a different application, side by side with each other, with different names.
Configuration of models in stu
That is, it is equivalent to creating a class under the models module and defining different methods under the class
from django.db import models
class Student(models.Model):
s_name = models.CharField(max_length=20)
s_gender = models.BooleanField()
class Meta:
db_table = 'stu'
database migration
1. The name of the database has been defined in the previous settings
2. Principle: Generate database files
3. Generate migration files
Command : python manage.py makemigrations
Perform database migration
1. On the basis of the previous step, execute the following command to migrate files.
2. Principle: Migrate data to the database
3. Complete the migration task
Command : python manage.py migrate