Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SQLModel fails to create DB constraints when using Annotated types after Pydantic 2.12.0 #1623

Labels
questionFurther information is requested
@YuriiMotov

Description

@YuriiMotov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp