From 120bbfce250b09eaf89848e92b12728b50970828 Mon Sep 17 00:00:00 2001 From: Flavius Raducu Date: Fri, 26 Sep 2025 19:32:42 +0100 Subject: [PATCH] update pk docs for sql databases to avoid confusion --- docs/en/docs/tutorial/sql-databases.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs/tutorial/sql-databases.md b/docs/en/docs/tutorial/sql-databases.md index cfa1c9073..ba231f32b 100644 --- a/docs/en/docs/tutorial/sql-databases.md +++ b/docs/en/docs/tutorial/sql-databases.md @@ -67,6 +67,10 @@ There are a few differences: 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`. + But inside the SQL database, the `id` is always required and can't be `NULL`. So, why should we declare it with `int | None`? + + The `id` will be required in the database, but it will be generated by the database, not by our code. + * `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. SQLModel will know that something declared as `str` will be a SQL column of type `TEXT` (or `VARCHAR`, depending on the database).