新增databases.py把所有建表基类统一成一个,才可以链接外键。
This commit is contained in:
+12
-6
@@ -5,17 +5,23 @@ from students.model import students_model
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
# 合并接口
|
||||
Students_API = APIRouter()
|
||||
Students_API.include_router(s_api)
|
||||
|
||||
# 自测接口
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
async def S_Router(Students_API: APIRouter):
|
||||
Base.metadata.create_all(engine1)
|
||||
yield
|
||||
engine1.dispose()
|
||||
|
||||
app = FastAPI(title="学生管理系统",lifespan=lifespan) # 这里必须把上面写的加上
|
||||
Students_API = APIRouter(lifespan=S_Router)
|
||||
Students_API.include_router(s_api)
|
||||
|
||||
# 自测接口
|
||||
@asynccontextmanager
|
||||
async def S_Fastapi(app: FastAPI):
|
||||
Base.metadata.create_all(engine1)
|
||||
yield
|
||||
engine1.dispose()
|
||||
|
||||
app = FastAPI(title="学生管理系统",lifespan=S_Fastapi) # 这里必须把上面写的加上
|
||||
app.include_router(s_api,tags=["students"])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user