We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
await site.db.async_run_sync(SQLModel.metadata.create_all, is_session=False)
sqlalchemy无法初始化自带的auth表,只能用sqlmodel
The text was updated successfully, but these errors were encountered:
You can use Base.metadata.create_all from sqlalchemy to create it. However, you need to bind and use the engine from AuthAdminSite.auth.db.
Base.metadata.create_all
sqlalchemy
bind
engine
AuthAdminSite.auth.db
from contextlib import asynccontextmanager from fastapi import FastAPI from app.api.v1.routes import V1Router from app.admin import admin_site # `AuthAdminSite` instance from app.admin import admin_auth # `AuthAdminSite.auth` instance from app.model.base import Base # `sqlachemy `2.0 `DeclarativeBase` # latest FastAPI version should use `asynccontextmanager` lifespan instead of `startup` event # https://fastapi.tiangolo.com/advanced/events/ @asynccontextmanager async def lifespan(app: FastAPI): # startup event todo # Note: **can't** use your `engine` instance, should use `AuthAdminSite.auth.db` instead Base.metadata.create_all(bind=admin_auth.db.engine) await admin_auth.create_role_user("admin") yield # shutdown event todo app = FastAPI( lifespan=lifespan, ) app.include_router(V1Router) admin_site.mount_app(app)
Sorry, something went wrong.
No branches or pull requests
await site.db.async_run_sync(SQLModel.metadata.create_all, is_session=False)
sqlalchemy无法初始化自带的auth表,只能用sqlmodel
The text was updated successfully, but these errors were encountered: