]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Update Primary Key notes for the SQL databases tutorial to avoid confusion (#14120)
authorFlavius <55413297+FlaviusRaducu@users.noreply.github.com>
Tue, 2 Dec 2025 05:06:56 +0000 (05:06 +0000)
committerGitHub <noreply@github.com>
Tue, 2 Dec 2025 05:06:56 +0000 (06:06 +0100)
docs/en/docs/tutorial/sql-databases.md

index cfa1c9073fe25862648ce7145615fc0b12022363..b42e9ba2f2a3babf640a92a9c93c34f54d73285a 100644 (file)
@@ -65,7 +65,7 @@ There are a few differences:
 
 * `Field(primary_key=True)` tells SQLModel that the `id` is the **primary key** in the SQL database (you can learn more about SQL primary keys in the SQLModel docs).
 
-    By having the type as `int | None`, SQLModel will know that this column should be an `INTEGER` in the SQL database and that it should be `NULLABLE`.
+    **Note:** We use `int | None` for the primary key field so that in Python code we can *create an object without an `id`* (`id=None`), assuming the database will *generate it when saving*. SQLModel understands that the database will provide the `id` and *defines the column as a non-null `INTEGER`* in the database schema. See <a href="https://sqlmodel.tiangolo.com/tutorial/create-db-and-table/#primary-key-id" class="external-link" target="_blank">SQLModel docs on primary keys</a> for details.
 
 * `Field(index=True)` tells SQLModel that it should create a **SQL index** for this column, that would allow faster lookups in the database when reading data filtered by this column.