ValueError: <class 'list'> has no matching SQLAlchemy type #995
Answered
by
ixycoexzckwpmlcu
mockingjet
asked this question in
Questions
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 |
Answered by
ixycoexzckwpmlcu
Jul 1, 2024
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
|
2 replies
Answer selected by
mockingjet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've tried to reproduce your example but couldn't. If I run your example verbatim, it errors with
NameError: name 'RolePermissionLink' is not defined1. If I change your example to the following: