You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d2adb99
Browse filesBrowse the repository at this point in the historyBrowse files
This keeps the previous database column type, so no database migration is needed for that field. It also adds the validation constraint described above.
143
143
144
144
To retain the previous database type **and** plain `datetime` validation behavior, declare the database type explicitly:
Copy file name to clipboardExpand all lines: docs/advanced/decimal.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ For the database, **SQLModel** will use [SQLAlchemy's `DECIMAL` type](https://do
33
33
34
34
Let's say that each hero in the database will have an amount of money. We can define that field as a `Decimal` and configure the maximum number of digits and decimal places using the parameters of `Field()`:
Here we are saying that `money` can have at most `5` digits with `max_digits`, **this includes the integers** (to the left of the decimal dot) **and the decimals** (to the right of the decimal dot).
39
39
@@ -67,13 +67,13 @@ Make sure you adjust the number of digits and decimal places for your own needs,
67
67
68
68
When creating new models you can actually pass normal (`float`) numbers, Pydantic will automatically convert them to `Decimal` types, and **SQLModel** will store them as `Decimal` types in the database (using SQLAlchemy).
Copy file name to clipboardExpand all lines: docs/tutorial/automatic-id-none-refresh.md
+9-13Lines changed: 9 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Now let's talk a bit about why the `id` field **can't be `NULL`** on the databas
6
6
7
7
But the same `id` field actually **can be `None`** in the Python code, so we declare the type with `int | None`, and set the default value to `Field(default=None)`:
And now, something unexpected happens, look at the output, it seems as if the `Hero` instance objects had no data at all:
106
106
@@ -158,7 +158,7 @@ We didn't access the object's attributes, like `hero.name`. We only accessed the
158
158
159
159
To confirm and understand how this **automatic expiration and refresh** of data when accessing attributes work, we can print some individual fields (instance attributes):
This way, you wouldn't have to deal with circular imports for other models.
73
73
@@ -77,15 +77,15 @@ And then you could import the models from this file/module in any other file/mod
77
77
78
78
Then you could put the code creating the **engine** and the function to create all the tables (if you are not using migrations) in another file `database.py`:
@@ -106,7 +106,7 @@ Now let's create one hero object to start.
106
106
107
107
As the `Hero` class model now has a field (column, attribute) `team_id`, we can set it by using the ID field from the `Team` objects we just created before:
0 commit comments