#36082: db_table does not truncate properly for the non-default database
-------------------------------------+-------------------------------------
Reporter: Scott | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
When getting db_table for a model, table name is truncated to
`connection.ops.max_name_length()`. See
[
https://github.com/django/django/blob/8bee7fa45cd7bfe70b68784314e994e2d193fd70/django/db/models/options.py#L235
here].
Since the name length is always calculated using `django.db.connection`,
it always truncates the table name based on the max length of the default
database. This causes issues when using multiple databases that have
different engines. For example, if we were using a SQLite default database
and a PostgreSQL secondary database, any table name longer than 63
characters will cause an error to be thrown.
This could be fixed by taking the minimum length when getting the table
name. I can put in a PR.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36082>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.