docs/release-notes.md
SQLModel.__new__, avoid explicitly returning Any. PR #1846 by @carljm.tuple_ return type annotation. PR #1639 by @kakeruzoku.contributing.md. PR #1842 by @GopalGB.HeroPublicWithTeam model. PR #1678 by @berkaykrc.target=_blank and CSS automatically in JS and CSS. PR #1799 by @tiangolo..in_() method. PR #619 by @masylum.typing-extensions. PR #1815 by @musicinmybrain.griffelib instead of griffe. PR #1775 by @svlandeg.sqlmodel-slim, no more versions will be released, use only sqmodel. PR #1772 by @tiangolo.expression.py. PR #1747 by @veeceey.session.execute() docstring & deprecation message. PR #1643 by @DanielLeviLucas.management-tasks.md to be in line with management-tasks.md in FastAPI repo. PR #1743 by @YuriiMotov.sqlmodel-slim. PR #1754 by @tiangolo.sqlmodel-slim, deprecate it, and make it only depend on sqlmodel. PR #1753 by @tiangolo.ValidationError schema in FastAPI-related tests to be compatible with FastAPI 0.128.1+. PR #1744 by @YuriiMotov.custom.js. PR #1711 by @alejsdev.read-relationships.md. PR #1705 by @stefmolin.uv.lock gets the internal label. PR #1719 by @svlandeg.>=0.103.2 in tests. PR #1709 by @YuriiMotov.deploy_docs_status.py. PR #1707 by @tiangolo.prek version pin to >=0.2.24,<1.0.0. PR #1698 by @YuriiMotov.alias support for Pydantic v2. PR #1577 by @ravishan16.RuntimeError: dictionary changed size during iteration in sqlmodel_update(). PR #997 by @BartSchuurmans.features.md. PR #1627 by @sparkiegeek.latest-changes GitHub Action and pin actions/checkout@v5. PR #1654 by @svlandeg.waiting label in issue-manager. PR #1609 by @YuriiMotov.model_dump for compatibility with the latest Pydantic versions. PR #1595 by @spazm.docs/tutorial/fastapi/simple-hero-api.md. PR #1583 by @kofi-kusi.docs/tutorial/relationship-attributes/cascade-delete-relationships.md. PR #1543 by @YuriiMotov.docs/tutorial/insert.md. PR #1368 by @brettcannon.docs/tutorial/fastapi/relationships.md. PR #1365 by @Foxerine.docs/learn/index.md. PR #1363 by @brettcannon.Optional to use the new syntax in Python 3.10, e.g. int | None. PR #1351 by @tiangolo.model.sqlmodel_update() instead of old setattr(). PR #1117 by @jpizquierdo.docs/virtual-environments.md. PR #1321 by @sylvainHellin.tests/test_tutorial/test_code_structure/test_tutorial001.py, one test file for multiple variants. PR #1408 by @tiangolo.clear_sqlmodel. PR #1406 by @tiangolo.tests/test_select_gen.py, pass environment variables, needed for NixOS nixpkgs. PR #969 by @pbsds.Field constructor. PR #1304 by @AlanBogarin.main branch. PR #1291 by @svlandeg.list instead of List. PR #1147 by @bubbletroubles.databases.md. PR #1113 by @radi-dev.docs/tutorial/create-db-and-table.md. PR #1252 by @ArianHamdi.insert.md. PR #1256 by @Noushadaliam.docs/advanced/uuid.md. PR #1151 by @tiangolo.docs/tutorial/create-db-and-table.md. PR #1149 by @tiangolo.indexes.md . PR #1100 by @alejsdev.labeler.yml. PR #1128 by @tiangolo.issue-manager.yml. PR #1103 by @tiangolo.include-hidden-files to True when using the upload-artifact GH action. PR #1098 by @svlandeg.Optional[Annotated[x, f()]], e.g. id: Optional[pydantic.UUID4]. PR #1093 by @tiangolo.docs/virtual-environments.md. PR #1085 by @tiangolo.cascade_delete docs. PR #1030 by @tiangolo.latest-changes GitHub Action. PR #1087 by @tiangolo.pyproject.toml, show up in PyPI. PR #1074 by @tiangolo.cascade_delete, ondelete, and passive_deletes. Initial PR #983 by @estebanx64.
docs/tutorial/create-db-and-table.md. PR #911 by @tfpgh.create-db-and-table-with-db-browser.md. PR #976 by @alejsdev.docs/tutorial. PR #943 by @luco17.sqlmodel/_compat.py. PR #950 by @Highfire1.docs/tutorial/relationship-attributes/index.md. PR #880 by @UncleGoogle.EmailStr support and max_length in several String subclasses. PR #966 by @estebanx64.max_length is set on Pydantic models using Pydantic v2. PR #963 by @estebanx64.TryCast used internally. PR #964 by @tiangolo.@dataclass_transform (now PEP 681) in docs/features.md. PR #753 by @soof-golan.In the future SQLModel will include the standard default recommended packages, and sqlmodel-slim will come without those recommended standard packages and with a group of optional dependencies sqlmodel-slim[standard], equivalent to sqlmodel, for those that want to opt out of those packages.
.sqlmodel_update() to update models in place, including an update parameter for extra data. And fix implementation for the (now documented) update parameter for .model_validate(). PR #804 by @tiangolo.
Field() with sa_type. PR #505 by @maru0123-2004.
sa_column excludes sa_column_args, primary_key, nullable, etc. PR #681 by @tiangolo.# in annotations (from MkDocs Material). PR #677 by @Matthieu-LAURENT39.Field parameters from Pydantic 1.9.0 and above, make Pydantic 1.9.0 the minimum required version. PR #440 by @daniil-berg.AsyncSession type annotations for exec(). PR #58 by @Bobronium.ForeignKey directly, remove repeated column construction from SQLModelMetaclass.__init__ and upgrade minimum SQLAlchemy to >=1.4.36. PR #443 by @daniil-berg.get_sqlalchemy_type. PR #669 by @tiangolo.1.4.29 (related to #434). PR #439 by @daniil-berg.docs/tutorial/create-db-and-table.md. PR #601 by @SimonCW.docs/tutorial/fastapi/multiple-models.md. PR #674 by @tiangolo.offset in example with limit and where. PR #273 by @jbmchuck.le (lte is invalid, use le ). PR #207 by @jrycw.docs/db-to-code.md. PR #649 by @MatveyF.docs/tutorial/relationship-attributes/define-relationships-attributes.md. PR #474 by @jalvaradosegura.get_sqlachemy_type(). PR #496 by @cmarqu.docs/tutorial/create-db-and-table.md. PR #477 by @FluffyDietEngine.strict = true instead of manual configs. PR #428 by @michaeloliverx.CITATION.cff file for academic citations. PR #13 by @sugatoray.nullable, allowing overrides in field. PR #423 by @JonasKs and @br-follow.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.