ValueError: <class 'list'> has no matching SQLAlchemy type #995
-
First Check
Commit to Help
Example Codefrom sqlmodel import Field, Relationship, SQLModel
class Role(SQLModel, table=True):
name: str = Field(index=True, unique=True)
permissions: list["Permission"] = Relationship(
back_populates="roles",
link_model=RolePermissionLink,
)
class Permission(SQLModel, table=True):
name: str = Field(index=True, unique=True)
roles: list[Role] = Relationship(
back_populates="permissions",
link_model=RolePermissionLink,
) DescriptionEither
Operating SystemLinux Operating System DetailsNo response SQLModel Version0.0.18 Python Version3.12.4 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I've tried to reproduce your example but couldn't. If I run your example verbatim, it errors with from sqlmodel import Field, Relationship, SQLModel
class RolePermissionLink(SQLModel, table=True):
role_id: str = Field(foreign_key="role.id", primary_key=True)
permission_id: str = Field(foreign_key="permission.id", primary_key=True)
class Role(SQLModel, table=True):
id: int = Field(primary_key=True)
name: str = Field(index=True, unique=True)
permissions: list["Permission"] = Relationship(
back_populates="roles",
link_model=RolePermissionLink,
)
class Permission(SQLModel, table=True):
id: int = Field(primary_key=True)
name: str = Field(index=True, unique=True)
roles: list[Role] = Relationship(
back_populates="permissions",
link_model=RolePermissionLink,
) ... then it works fine (no console output). Footnotes |
Beta Was this translation helpful? Give feedback.
I've tried to reproduce your example but couldn't. If I run your example verbatim, it errors with
NameError: name 'RolePermissionLink' is not defined
1. If I change your example to the following: