0

我正在尝试使用 SQLModel ( https://sqlmodel.tiangolo.com/ ),并且我不得不在几个字段之间创建一个复合索引,而我无法使用 SQLModel 库来做到这一点。

数据库模型

我发现的唯一解决方法是直接使用 sqlalchemy 索引,而不是 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"
    ),
)
4

0 回答 0