From 91f1b6dcdc5da47d7794a55e3114820407a5bd62 Mon Sep 17 00:00:00 2001 From: Anubhav Joshi Date: Tue, 10 Jun 2014 17:34:19 +0530 Subject: Fixed #13711 -- Model check added to ensure that auto-generated column name is within limits of the database. Thanks russellm for report and Tim Graham for review. --- docs/ref/checks.txt | 5 +++++ docs/releases/1.8.txt | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'docs') diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt index aedaa921db..85cd616253 100644 --- a/docs/ref/checks.txt +++ b/docs/ref/checks.txt @@ -58,6 +58,11 @@ Models * **models.E016**: ``index_together/unique_together`` refers to field ```` which is not local to model ````. * **models.E017**: Proxy model ```` contains model fields. +* **models.E018**: Autogenerated column name too long for field ````. + Maximum length is ```` for database ````. +* **models.E019**: Autogenerated column name too long for M2M field + ````. Maximum length is ```` for database + ````. Fields ~~~~~~ diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index c54e1d5ab0..7f3b4aa6c7 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -305,6 +305,28 @@ Now to implement the same behavior, you have to create an ``parser.add_argument`` to add any custom arguments, as parser is now an :py:class:`argparse.ArgumentParser` instance. +Model check ensures auto-generated column names are within limits specified by database +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A field name that's longer than the column name length supported by a database +can create problems. For example, with MySQL you'll get an exception trying to +create the column, and with PostgreSQL the column name is truncated by the +database (you may see a warning in the PostgreSQL logs). + +A model check has been introduced to better alert users to this scenario before +the actual creation of database tables. + +If you have an existing model where this check seems to be a false positive, +for example on PostgreSQL where the name was already being truncated, simply +use :attr:`~django.db.models.Field.db_column` to specify the name that's being +used. + +The check also applies to the columns generated in an implicit +``ManyToManyField.through`` model. If you run into an issue there, use +:attr:`~django.db.models.ManyToManyField.through` to create an explicit model +and then specify :attr:`~django.db.models.Field.db_column` on its column(s) +as needed. + Miscellaneous ~~~~~~~~~~~~~ -- cgit v1.3