ORM
Object Relational ing (ORM for short) is a technology designed to solve the problem of non-matching between objects and relational databases.
By using metadata that describes the ing between objects and databases, the objects in the program are automatically persisted to the relational database.
Advantages:
The main problem solved by ORM is the ing between objects and relationships. It usually maps a class to a table. each instance of the class corresponds to a record in the table, and each attribute of the class corresponds to each field in the table. Orm provides database ing. You do not need to write SQL code directly. You only need to operate on objects to operate data on the database. It enables software developers to focus on business logic processing and improves development efficiency.
Disadvantages:
The disadvantage of ORM is that it will sacrifice the execution efficiency of the program to a certain extent. Orm operations are limited, that is, operations defined by ORM can be completed, and some complex query operations cannot be completed.
Use the MySQL database in the Django Project
Set in settings
Databases = {"default": {"engine": "Django. DB. backends. mySQL "," name ":" Your Database Name ", # You need to manually create a database" user ":" database username "," password ":" Database Password ", "host": "database IP Address", "Post": 3306 }}
Write the following code in the _ init _. py file in the directory with the same name as the Django project to tell Django to connect to the MySQL database using the pymysql module:
import pymysql pymysql.install_as_MySQLdb()
Models
Model is a single and clear source of your data. It contains important fields and actions of the data you store. A model is usually mapped to a database table.
Below are the Mappings
Django models and ORM