Skip to content

How to deal with column type needed situation? #1517

Answered by YuriiMotov
Ma233 asked this question in Questions
Discussion options

You must be logged in to vote

In both cases you should use col() (from sqlmodel import col):

from sqlmodel import (
    Field,
    SQLModel,
    UniqueConstraint,
    col,
    select,
)


class BookCollection(SQLModel, table=True):
    id: int = Field(primary_key=True)
    user_nid: int
    book_nid: int


UniqueConstraint(
    col(BookCollection.user_nid),
    col(BookCollection.book_nid),
    name="uidx_book_collection_user_nid_book_nid",
)

select(BookCollection).where(col(BookCollection.book_nid).not_in([1, 2, 3]))

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
3 participants
Converted from issue

This discussion was converted from issue #95 on August 13, 2025 15:41.