Skip to content

ValueError: <class 'list'> has no matching SQLAlchemy type #995

Discussion options

You must be logged in to vote

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:

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 Pe…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mockingjet
Comment options

@mockingjet
Comment options

Answer selected by mockingjet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants