SQL databases in Python, designed for simplicity, compatibility, and robustness.
nullable
, allowing overrides in field. PR #423 by @JonasKs.expresion.py
, sync from Jinja2 template, implement inherit_cache
to solve errors like: SAWarning: Class SelectOfScalar will not make use of SQL compilation caching
. PR #422 by @tiangolo.docs/tutorial/create-db-and-table.md
. PR #426 by @tiangolo.docs/tutorial/connect/remove-data-connections.md
. PR #421 by @VerdantFox.unique
in Field()
for a column. PR #83 by @raphaelgibson.UUID.hex
instead of an int
. PR #26 by @andrewbolster.Session.get()
parameter execution_options
. PR #302 by @tiangolo.Model.parse_obj()
, and Model.validate()
. PR #321 by @phi-friday.Select
and SelectOfScalar
to inherit cache to avoid warning: SAWarning: Class SelectOfScalar will not make use of SQL compilation caching
. PR #234 by @rabinadk1.None
. PR #79 by @van51.id
should not be updatable. PR #335 by @kurtportelli.hero_spider_boy.id
=> hero_spider_boy.team_id
. PR #106 by @yoannmos.docs/databases.md
and docs/tutorial/index.md
. PR #35 by @prrao87.docs/tutorial/relationship-attributes/define-relationships-attributes.md
. PR #239 by @jalvaradosegura.docs/tutorial/fastapi/simple-hero-api.md
. PR #80 by @joemudryk.docs/tutorial/code-structure.md
. PR #344 by @marciomazza.docs/db-to-code.md
. PR #155 by @gr8jam.docs/contributing.md
. PR #323 by @Fardad13.docs/tutorial/fastapi/tests.md
. PR #265 by @johnhoman.docs/tutorial/where.md
. PR #286 by @jalvaradosegura.docs/tutorial/fastapi/update.md
. PR #268 by @cirrusj.docs/tutorial/fastapi/simple-hero-api.md
. PR #247 by @hao-wang.docs/tutorial/automatic-id-none-refresh.md
, docs/tutorial/fastapi/update.md
, docs/tutorial/select.md
. PR #185 by @rootux.docs/databases.md
. PR #177 by @seandlg.docs/tutorial/fastapi/update.md
. PR #162 by @wmcgee3.docs/tutorial/code-structure.md
, docs/tutorial/fastapi/multiple-models.md
, docs/tutorial/fastapi/simple-hero-api.md
, docs/tutorial/many-to-many/index.md
. PR #116 by @moonso.docs/tutorial/fastapi/teams.md
. PR #154 by @chrisgoddard.back_populates
, always use hero
instead of owner
. PR #120 by @onionj.docs/tutorial/fastapi/tests.md
. PR #113 by @feanil.docs/tutorial/where.md
. PR #72 by @ZettZet.docs/tutorial/code-structure.md
. PR #91 by @dhiraj.docs/help.md
. PR #84 by @mborus.docs/tutorial/many-to-many/create-models-with-link.md
. PR #45 by @xginn8.docs/tutorial/index.md
. PR #398 by @ryangrose.^0.68.0
to ^0.68.1
. PR #48 by @alucarddelta.==1.2.0b1
. PR #303 by @tiangolo.SQLModel no longer creates indexes by default for every column, indexes are now opt-in. You can read more about it in PR #205.
Before this change, if you had a model like this:
from typing import Optional
from sqlmodel import Field, SQLModel
class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str
secret_name: str
age: Optional[int] = None
...when creating the tables, SQLModel version 0.0.5
and below, would also create an index for name
, one for secret_name
, and one for age
(id
is the primary key, so it doesn't need an additional index).
If you depended on having an index for each one of those columns, now you can (and would have to) define them explicitly:
class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True)
secret_name: str = Field(index=True)
age: Optional[int] = Field(default=None, index=True)
There's a high chance you don't need indexes for all the columns. For example, you might only need indexes for name
and age
, but not for secret_name
. In that case, you could define the model as:
class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True)
secret_name: str
age: Optional[int] = Field(default=None, index=True)
If you already created your database tables with SQLModel using versions 0.0.5
or below, it would have also created those indexes in the database. In that case, you might want to manually drop (remove) some of those indexes, if they are unnecessary, to avoid the extra cost in performance and space.
Depending on the database you are using, there will be a different way to find the available indexes.
For example, let's say you no longer need the index for secret_name
. You could check the current indexes in the database and find the one for secret_name
, it could be named ix_hero_secret_name
. Then you can remove it with SQL:
DROP INDEX ix_hero_secret_name
or
DROP INDEX ix_hero_secret_name ON hero;
Here's the new, extensive documentation explaining indexes and how to use them: Indexes - Optimize Queries.
docs/tutorial/automatic-id-none-refresh.md
. PR #14 by @leynier.docs/tutorial/index.md
and docs/databases.md
. PR #5 by @sebastianmarines.expression.py
and expression template, currently needed by CI. PR #187 by @tiangolo.