我是Python新手.
我的项目是使用SQLAlchemy,Alembic和MyPy.
我有一对父子类定义如下(省略了一堆细节):
class RawEmergency(InputBase, RawTables):
__tablename__ = "emergency"
id: Mapped[UNIQUEIDENTIFIER] = mapped_column(
UNIQUEIDENTIFIER(), primary_key=True, autoincrement=False
)
attendance_id: Mapped[str | None] = guid_column()
admitted_spell_id: Mapped[str | None] = guid_column()
__table_args__ = (
PrimaryKeyConstraint("id", mssql_clustered=False),
Index(
"index_emergency_pii_patient_id_and_datetimes",
pii_patient_id,
attendance_start_date.desc(),
attendance_start_time.desc(),
),
)
class InputBase(DeclarativeBase):
metadata = MetaData(schema="raw")
refresh_date: Mapped[str] = date_str_column()
refresh_time: Mapped[str] = time_str_column()
class RawTables(object):
id: Mapped[UNIQUEIDENTIFIER] = mapped_column(
UNIQUEIDENTIFIER(), primary_key=True, autoincrement=False
)
__table_args__: typing.Any = (
PrimaryKeyConstraint(name="id", mssql_clustered=False),
)
我想向紧急情况表添加第二个索引,为基表提供的刷新列建立索引.
我希望通过在__table_args__
设置中添加额外的Index()
调用来实现这一点.
然后,我想运行我的标准迁移创建/判断工具:
poetry run alembic --config operator_app/alembic.ini revision --autogenerate -m "refresh_col_indexes"
个
如何引用这个声明中的刷新列?
当前已失败的attem猜测:
Index(
"index_emergency_refresh_date_time",
refresh_date.desc(),
refresh_time.desc(),
),
mypy和IDE都说他们不知道refresh_date
是什么
error: Name "refresh_date" is not defined [name-defined]
Index(
"index_emergency_refresh_date_time",
InputBase.refresh_date.desc(),
InputBase.refresh_time.desc(),
),
现在编译,但alembic命令不起作用:
sqlalchemy.exc.ArgumentError: Can't add unnamed column to column collection full error below
个
Index(
"index_emergency_refresh_date_time",
super().refresh_date.desc(),
super().refresh_time.desc(),
),
Mypy/IDE说不:
error: "super()" outside of a method is not supported
个
Index(
"index_emergency_refresh_date_time",
super(InputBase, self).refresh_date.desc(),
super(InputBase, self).refresh_time.desc(),
),
self is not defined
Index(
"index_emergency_refresh_date_time",
super(InputBase, None).refresh_date.desc(),
super(InputBase, None).refresh_time.desc(),
),
mypy说Unsupported argument 2 for "super"
Alembic说AttributeError: 'super' object has no attribute 'refresh_date'