ORM单表操作

一.ORM简介

image

image

二.ORM字段操作

1.增

image

2.改/删

image

3.迁移操作

image

三.ORM数据操作

1.增

image

2.改

image

3.删

image

4.查

image

四.ORM创建表关系

1.一对一

image

2.一对多

image

3.多对多

image

3.两个不同的应用中的数据表之间关联起来

"""假设在项目中有app01和app02两个应用,两个应用的models.py文件中分别有User和Book两个类,要将app02中Book类的author字段设置外键,与app01中的User类关联起来,方法如下:"""

1、首先在app02的models.py文件中引入User,如下:
from app01.models import User

2、设置外键字段为:
author = models.ForeignKey(to=User,on_delete=models.CASCADE)

## 这其中需要注意的是,User一定不能加引号,否则会报以下错误:
video.Video.videoAuthor: (fields.E300) Field defines a relation with model 'User', which is either not installed, or is abstract.

五.ORM查询汇总

image
image

六.基于双下滑线的查询

image
image

posted @ 2022-02-25 17:43  xiaoyuanjiangjin  阅读(50)  评论(0)    收藏  举报