我正在尝试 SQLModel ( https://sqlmodel.tiangolo.com/ ),我发现我必须在多个字段之间创建复合索引,但我不知道如何使用 SQLModel 库来做到这一点。
我发现的唯一解决方法是直接使用 sqlalchemy Index,而不是 index=true (来自为唯一字段创建索引时的 SQLModel 文档 - )
class Jump(SQLModel, table=True):
"""
SQL Table abstraction: Jump
Contains data belonging to a connection between a questionnaire-version
and another questionnaire-version
"""
origin_name: str = Field(primary_key=True)
origin_version: int = Field()
destination_name: str = Field()
__table_args__ = (
Index(
"compound_index_origin_name_version_destination_name",
"origin_name",
"origin_version",
"destination_name",
),
)
Run Code Online (Sandbox Code Playgroud)