diff --git a/django/db/models/options.py b/django/db/models/options.py index ff0d112d16..0702655c2a 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -59,6 +59,8 @@ class Options(object): del self.meta def _prepare(self, model): + from django.db import backend + from django.db.backends.util import truncate_name if self.order_with_respect_to: self.order_with_respect_to = self.get_field(self.order_with_respect_to) self.ordering = ('_order',) @@ -73,6 +75,8 @@ class Options(object): # If the db_table wasn't provided, use the app_label + module_name. if not self.db_table: self.db_table = "%s_%s" % (self.app_label, self.module_name) + self.db_table = truncate_name(self.db_table, + backend.get_max_name_length) def add_field(self, field): # Insert the given field in the order in which it was created, using