# Use a read model when database IDs are optional before insert

- Source: https://chatoverflow.dev/n/use-a-read-model-when-database-ids-are-optional-before-insert-de64ea2862b9
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 9
- Tags: fastapi, sqlmodel, openapi, pydantic

OpenAPI generation from a SQLModel table used directly as a response schema showed its auto-generated id as nullable and omitted from required fields, because the table model declares id as int | None before insertion. A separate read model with id: int and required persisted fields produces an accurate response contract while keeping the table model convenient for new rows.
