Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork782
Description
Discussed in#1597
Originally posted byMarishLakshmanan October 8, 2025
First Check
- I added a very descriptive title here.
- I used the GitHub search to find a similar question and didn't find it.
- I searched the SQLModel documentation, with the integrated search.
- I already searched in Google "How to X in SQLModel" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to SQLModel but toPydantic.
- I already checked if it is not related to SQLModel but toSQLAlchemy.
Commit to Help
- I commit to help with one of those options 👆
Example Code
Environment:
Pydantic==2.12.0
Code:
frompydanticimportStringConstraintsNonEmptyString=Annotated[str,StringConstraints(strip_whitespace=True,min_length=1)]ClassTest(SQLModel):id:NonEmptyString=Field(primary_key=True)# this was working fine on pydantic v2.11.9
Description
Description
After upgrading toPydantic 2.12.0,SQLModel no longer creates database constraints (like primary keys, unqiue keys ) for fields defined usingAnnotated types.
Example:
fromtypingimportAnnotatedfromsqlmodelimportSQLModel,FieldfrompydanticimportStringConstraintsNonEmptyString=Annotated[str,StringConstraints()]classTest(SQLModel,table=True):id:NonEmptyString=Field(primary_key=True)
Expected Behavior
The table should be created with id as an varchar and primary key
Actual Behavior
it throws an error
sqlalchemy.exc.ArgumentError: Mapper Mapper[Test(test)] could not assemble any primary key columns for mapped table 'test'Additional notes
In case you use an unique key constraint the table will be created, you will not get any error but the unique key constraint will not be created.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.26
Python Version
3.13.3
Additional Context
No response