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
Copy file name to clipboardExpand all lines: CHANGELOG.rst
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,19 @@ Changelog
8
8
1.1
9
9
===
10
10
11
+
1.1.1
12
+
-----
13
+
14
+
Added
15
+
^^^^^
16
+
- **``SqlDefault`` and ``Now`` expressions for ``db_default``** — use ``db_default=SqlDefault("...")`` to emit raw SQL expressions (e.g. ``CURRENT_TIMESTAMP``) as database defaults. ``Now()`` is a convenience shorthand for ``SqlDefault("CURRENT_TIMESTAMP")``. (#2104)
17
+
18
+
19
+
Changed
20
+
^^^^^^^
21
+
- ``Field(default=...)`` and ``auto_now`` / ``auto_now_add`` no longer emits a ``DEFAULT`` clause in ``generate_schemas()``. The ``default`` parameter is Python-only; use ``db_default`` for database-level defaults. This aligns ``generate_schemas()`` with migrations, which don't emitted ``DEFAULT`` for ``default=``. (#2104)
Copy file name to clipboardExpand all lines: docs/models.rst
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,18 @@ Every model should be derived from ``Model`` or its subclasses. Custom ``Model``
71
71
This model will not affect the schema, but it will be available for inheritance.
72
72
73
73
74
-
Further we have field ``fields.DatetimeField(auto_now=True)``. Options ``auto_now`` and ``auto_now_add`` work like Django's options.
74
+
Further we have field ``fields.DatetimeField(auto_now=True)``. Options ``auto_now`` and ``auto_now_add`` work like Django's options — they are handled purely in Python and do **not** add a ``DEFAULT`` clause to the database schema. If you need a database-level default timestamp, use ``db_default``:
75
+
76
+
.. code-block:: python3
77
+
78
+
from tortoise.fields import DatetimeField, Now
79
+
80
+
class MyModel(Model):
81
+
# Python-only: value set by ORM on save, no DB DEFAULT
82
+
modified = DatetimeField(auto_now=True)
83
+
84
+
# DB-level: emits DEFAULT CURRENT_TIMESTAMP in the schema
0 commit comments