Use the models in Django to operate the database

1. First enter the settings


2. Declare data types in models

    2.1 First introduce the required toolkit

import MySQLdb

    2.2 Create the type of each field of the table table


 2.3 Customize the name of the table


2.4 After executing the above, the next step is to run the command to create the table

Open run manage.py task and execute makemigrations to generate database change files

Execute the migrate command to execute the database change file


If you need to modify the data model class, you must first execute makemigrations to generate the data model change file, and execute the change file after executing migrate

After the execution has completed the creation of the database table

Guess you like

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