Skip to content
Discussion options

You must be logged in to vote

The fact that validation doesn't work for "table" models is a limitation of SQLModel, but it doesn't mean that it's useless.
It still helps avoid duplication (no need to duplicate fields):

class CategoryBase(SQLModel): name: str = Field(index=True, unique=True, max_length=30, min_length=3) class Category(CategoryBase, table=True): id: Optional[int] = Field(primary_key=True, default=None) class CreateCategory(CategoryBase): pass

The code example below works. It creates unique constraint, and it validates input values.

from typing import Optional from fastapi import FastAPI from sqlmodel import Field, Session, SQLModel, create_engine class CategoryBase(SQLModel): name: str 

Replies: 1 comment

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
2 participants