fastapi:alembic找不到models目录下的数据表model
两个要注意的环节:
一:alembic/env.py
要有这一行把models下的类引入:
from app.models import *
如下:
from app.db.dbbase import MyBaseModel
from app.models import * # noqa: F401,F403
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
# target_metadata = None
target_metadata = MyBaseModel.metadata
二:models/__init__.py
要把models目录下的类都包含进来
# app/models/__init__.py
from app.models.app_user import AppUser
__all__ = ["AppUser"]
浙公网安备 33010602011771号