Discussed in #1597
Originally posted by MarishLakshmanan October 8, 2025
First Check
Commit to Help
Example Code
Environment:
Pydantic==2.12.0
Code:
from pydantic import StringConstraints
NonEmptyString = Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)]
Class Test(SQLModel):
id: NonEmptyString = Field(primary_key=True) # this was working fine on pydantic v2.11.9
Description
Description
After upgrading to Pydantic 2.12.0, SQLModel no longer creates database constraints (like primary keys, unqiue keys ) for fields defined using Annotated types.
Example:
from typing import Annotated
from sqlmodel import SQLModel, Field
from pydantic import StringConstraints
NonEmptyString = Annotated[str, StringConstraints()]
class Test(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
Discussed in #1597
Originally posted by MarishLakshmanan October 8, 2025
First Check
Commit to Help
Example Code
Environment:
Pydantic==2.12.0
Code:
Description
Description
After upgrading to Pydantic 2.12.0,
SQLModelno longer creates database constraints (like primary keys, unqiue keys ) for fields defined usingAnnotatedtypes.Example:
Expected Behavior
The table should be created with id as an varchar and primary key
Actual Behavior
it throws an error
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