primary_key=True in Field not work when sa_column argument exists #573
-
First Check
Commit to Help
Example Code##Not work
class ResourceType(SQLModel, table=True):
resourceTypeID: int = Field(sa_column=Column(SmallInteger),primary_key=True
index=True, )
# Work
class ResourceTypeOK(SQLModel, table=True):
resourceTypeID: int = Field(sa_column=Column(SmallInteger,primary_key=True)
index=True, ) DescriptionError: sqlalchemy.exc.ArgumentError: Mapper Mapper[ResourceType(resourcetype)] could not assemble any primary key columns for mapped table 'resourcetype' Operating SystemWindows Operating System DetailsNo response SQLModel Version0.0.8 Python VersionPython 3.11.2 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
YuriiMotov
Aug 19, 2025
Replies: 2 comments
-
On similar lines
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, if you specify class ResourceTypeOK(SQLModel, table=True):
resourceTypeID: int = Field(
sa_column=Column(SmallInteger, primary_key=True, index=True),
) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YuriiMotov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, if you specify
sa_column
you should then passprimary_key=True
,index=True
and other column-related parameters as parameters toColumn
: