sqlmodel

Defines SQLModel table models and async session query patterns for FastAPI data layers.

Updated Sep 13, 2026
One-click install
npx skills add https://github.com/abdulazeezoj/monovella-poc --skill sqlmodel-abdulazeezoj
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlmodel
Source: https://github.com/abdulazeezoj/monovella-poc/tree/main/.agents/skills/sqlmodel
Command: npx skills add https://github.com/abdulazeezoj/monovella-poc --skill sqlmodel-abdulazeezoj

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires sqlmodel, sqlalchemy, pydantic, and includes references (resource) components.

What problem does it solve? Working in a SQLModel-based FastAPI project, it's easy to introduce a second, inconsistent style: mixing up .exec() with .execute(), forgetting await on session calls, or collapsing table models and API schemas into one type. This Skill encodes the project's exact conventions so new models, queries, and session code match the existing data layer. ## Core Features & Use Cases - Table Model Conventions: Shows how to define SQLModel classes with table=True, Field(...) options, and primary keys matching the project's models.py. - Async Session Patterns: Documents the engine/session setup in db.py, the get_session() dependency, and the full read/write cycle with session.exec(), get(), commit(), and refresh(). - Gotcha Prevention: Explains the missing-await coroutine trap, the .exec() vs .execute() mismatch, and Alembic model-import visibility for autogenerate. - Use Case: When adding a new widgets table, follow the included guide to define the model, create separate WidgetCreate/WidgetRead Pydantic schemas, write CRUD queries, and hand off to Alembic for the migration. ## Quick Start Ask the AI to add a new SQLModel table model with its CRUD queries following this project's conventions.

Frequently Asked Questions about sqlmodel

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a SQLModel table model in FastAPI?

Create a class inheriting SQLModel with table=True, using type-annotated attributes as columns and Field(...) for options like primary_key=True or foreign_key. Place it in the project's models.py so Alembic autogenerate can see it.

What is the difference between session.exec() and session.execute() in SQLModel?

session.exec() is SQLModel's method that returns model instances directly, while session.execute() is inherited from SQLAlchemy and returns rows needing an extra .scalars() call. In a SQLModel project, always use .exec() to avoid confusing downstream validation errors.

Why does my SQLModel query return a coroutine object instead of data?

A missing await on an async session call returns a coroutine instead of results, failing later with an AttributeError like 'coroutine' object has no attribute 'all'. Every database-touching call (exec, get, commit, refresh, delete) must be awaited.

Should SQLModel table models and Pydantic API schemas be the same class?

This project keeps them separate: the table model lives in models.py while ItemCreate/ItemRead plain Pydantic models live in schemas.py. Request, response, and storage shapes diverge once you add server-assigned IDs, secrets, or computed fields.

Why doesn't Alembic autogenerate detect my new SQLModel table?

Alembic's autogenerate only sees tables whose model class has been imported before it runs, since target_metadata points at SQLModel.metadata. Keep new models importable from models.py or ensure env.py imports the module defining them.