
























本系列汇总,请查看这里:https://www.cnblogs.com/uncleyong/p/19503695
删除前,数据库数据


student.py
from typing import List
from fastapi import APIRouter
from fastapi.exceptions import HTTPException
from pydantic import BaseModel, field_validator
from test_orm.models import Student, Course
student_api = APIRouter()
@student_api.delete("/{student_id}")
async def deleteStudent(student_id: int):
deleteCount = await Student.filter(id=student_id).delete()
if not deleteCount:
raise HTTPException(status_code=404, detail=f"主键为{student_id}的学生不存在")
return {}
请求数据

响应结果

删除后,数据库数据


总结:关联表的数据也删除了。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。