Opened 4 hours ago
Closed 3 hours ago
#36082 closed Bug (duplicate)
db_table does not truncate properly for the non-default database
Reported by: | Scott | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Scott | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When getting db_table for a model, table name is truncated to connection.ops.max_name_length()
. See 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.
Duplicate of #13528. Unfortunately, it's a complicated issue.