Skip to content

feat: add Meta.db_table alias for table name#2207

Open
waketzheng wants to merge 3 commits into
tortoise:developfrom
waketzheng:support-db-table
Open

feat: add Meta.db_table alias for table name#2207
waketzheng wants to merge 3 commits into
tortoise:developfrom
waketzheng:support-db-table

Conversation

@waketzheng
Copy link
Copy Markdown
Contributor

Description

Add Meta.db_table as an alias for Meta.table when configuring model table names.

This change allows:

  • table = "custom_table"
  • db_table = "custom_table"
  • both table and db_table when they have the same value

If both options are set with different values, model creation raises ConfigurationError.

The model documentation has also been updated to mention db_table.

Motivation and Context

Users coming from Django often expect Meta.db_table to customize the database table name. Previously, Tortoise ORM only recognized Meta.table, so db_table was silently ignored.

Supporting db_table makes the behavior friendlier for Django users while keeping the existing table option fully backward compatible.

How Has This Been Tested?

Tested on Windows with Python 3.14.3.

Commands run:

uv run --frozen --group test pytest tests/test_table_name.py
uv run --frozen ruff check tortoise tests

tests/test_table_name.py now covers:

  • Meta.table still taking precedence over the global table name generator
  • Meta.db_table working as a table name override
  • matching Meta.table and Meta.db_table
  • conflicting Meta.table and Meta.db_table raising ConfigurationError

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 29, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing waketzheng:support-db-table (d3e11fd) with develop (179ea6f)

Open in CodSpeed

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.

1 participant