Generate SQLAlchemy Model + Pydantic Schemas
When to Use
Use this skill when creating a new database model with its Pydantic schemas for a FastAPI project.
Instructions
Read existing models for conventions (Base class, naming, mixins).
Generate the SQLAlchemy model:
- Use appropriate column types
- Add indexes on frequently queried columns
- Set
nullable=Falsewhere data is required - Add relationship definitions with
back_populates - Add
__repr__for debugging
Generate Pydantic schemas:
Baseschema with shared fieldsCreateschema for POST requestsResponseschema withmodel_config = ConfigDict(from_attributes=True)Updateschema with all fields optional (field: type | None = None)- Use
Annotated[type, Field(...)]for validation - Use
@field_validator(v2 syntax)
Generate the Alembic migration command:
alembic revision --autogenerate -m "add <model_name> table" alembic upgrade head
Source: RoninForge/roninforge-fastapi — distributed by TomeVault.