小编Adr*_*cía的帖子

复合索引 SQLModel

我正在尝试 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)

python database indexing model sqlmodel

9
推荐指数
1
解决办法
1698
查看次数

标签 统计

database ×1

indexing ×1

model ×1

python ×1

sqlmodel ×1