Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12977 -- Ensure that indexes don't exceed character limits on …

…MySQL. Thanks to carljm for the original report, and hgeerts@osso.nl for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13040 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9d8492c169d54b727ab387132456d4c1526cff06 1 parent 4e0aa65
Russell Keith-Magee authored April 28, 2010
5  django/db/backends/creation.py
@@ -260,6 +260,8 @@ def sql_indexes_for_model(self, model, style):
260 260
 
261 261
     def sql_indexes_for_field(self, model, f, style):
262 262
         "Return the CREATE INDEX SQL statements for a single model field"
  263
+        from django.db.backends.util import truncate_name
  264
+
263 265
         if f.db_index and not f.unique:
264 266
             qn = self.connection.ops.quote_name
265 267
             tablespace = f.db_tablespace or model._meta.db_tablespace
@@ -271,8 +273,9 @@ def sql_indexes_for_field(self, model, f, style):
271 273
                     tablespace_sql = ''
272 274
             else:
273 275
                 tablespace_sql = ''
  276
+            i_name = '%s_%s' % (model._meta.db_table, self._digest(f.column))
274 277
             output = [style.SQL_KEYWORD('CREATE INDEX') + ' ' +
275  
-                style.SQL_TABLE(qn('%s_%s' % (model._meta.db_table, f.column))) + ' ' +
  278
+                style.SQL_TABLE(qn(truncate_name(i_name, self.connection.ops.max_name_length()))) + ' ' +
276 279
                 style.SQL_KEYWORD('ON') + ' ' +
277 280
                 style.SQL_TABLE(qn(model._meta.db_table)) + ' ' +
278 281
                 "(%s)" % style.SQL_FIELD(qn(f.column)) +
3  django/db/backends/mysql/base.py
@@ -227,6 +227,9 @@ def year_lookup_bounds(self, value):
227 227
         second = '%s-12-31 23:59:59.99'
228 228
         return [first % value, second % value]
229 229
 
  230
+    def max_name_length(self):
  231
+        return 64
  232
+
230 233
 class DatabaseWrapper(BaseDatabaseWrapper):
231 234
 
232 235
     operators = {

1 note on commit 9d8492c

Trinh Hoang Nhu

Hey django 1.4.3 meet this bug again :(

Please sign in to comment.
Something went wrong with that request. Please try again.