Skip to content

Conversation

@abondar
Copy link
Member

@abondar abondar commented Feb 11, 2026

Added explicit param for propagating value as default in database

Resolved #2091

AI summary:
This pull request introduces support for database-level default values (db_default) for fields, which allows default values to be enforced at the schema/database level rather than just in Python. This feature is reflected in the changelog, new migration examples, and updates to model and test code to ensure correct handling and description of db_default. The changes also include improvements to migration operations and model construction utilities.

New features and schema enhancements:

  • Added a db_default parameter for fields, enabling database-level DEFAULT clauses that persist in schema generation and migrations. This allows defaults to be enforced for rows inserted outside the ORM. (CHANGELOG.rst, CHANGELOG.rstL13-R28)
  • Updated Product model in models.py to include stock_quantity with a db_default value, and new migration files demonstrate adding, changing, and dropping db_default values for fields. (models.py, [1]; migrations/0018_add_db_defaults.py, [2]; migrations/0019_change_db_default.py, [3]; migrations/0020_drop_db_default.py, [4]

Testing and introspection improvements:

Migration and utility enhancements:

  • Added migration operations for setting, changing, and removing db_default values, ensuring schema changes are correctly handled and tested. (migrations/0018_add_db_defaults.py, [1]; migrations/0019_change_db_default.py, [2]; migrations/0020_drop_db_default.py, [3]

Changelog and documentation updates:

  • Updated CHANGELOG.rst to document the new db_default feature, model construction improvements, and several bug fixes.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 11, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing feature/db-default (9eaad62) with develop (1420fb0)

Open in CodSpeed

@abondar abondar merged commit 33bb44f into develop Feb 11, 2026
25 checks passed
@abondar abondar deleted the feature/db-default branch February 11, 2026 20:11
@coveralls
Copy link

Pull Request Test Coverage Report for Build 21921064235

Details

  • 45 of 55 (81.82%) changed or added relevant lines in 5 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.008%) to 82.661%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tortoise/migrations/schema_editor/base.py 20 21 95.24%
tortoise/backends/base/schema_generator.py 5 7 71.43%
tortoise/migrations/schema_editor/sqlite.py 2 9 22.22%
Files with Coverage Reduction New Missed Lines %
tortoise/migrations/schema_editor/sqlite.py 1 25.71%
Totals Coverage Status
Change from base Build 21919210961: -0.008%
Covered Lines: 10584
Relevant Lines: 12340

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Field default values are ignored in schema editor (migrations)

2 participants