Ticket #13434: django-mysql-index-length.patch

File django-mysql-index-length.patch, 1.6 KB (added by hgeerts@…, 14 years ago)
  • django/db/backends/mysql/base.py

     
    227227        second = '%s-12-31 23:59:59.99'
    228228        return [first % value, second % value]
    229229
     230    def max_name_length(self):
     231        return 64
     232
    230233class DatabaseWrapper(BaseDatabaseWrapper):
    231234
    232235    operators = {
  • django/db/backends/creation.py

     
    260260
    261261    def sql_indexes_for_field(self, model, f, style):
    262262        "Return the CREATE INDEX SQL statements for a single model field"
     263        from django.db.backends.util import truncate_name
     264
    263265        if f.db_index and not f.unique:
    264266            qn = self.connection.ops.quote_name
    265267            tablespace = f.db_tablespace or model._meta.db_tablespace
     
    271273                    tablespace_sql = ''
    272274            else:
    273275                tablespace_sql = ''
     276            i_name = '%s_%s' % (model._meta.db_table, self._digest(f.column))
    274277            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()))) + ' ' +
    276279                style.SQL_KEYWORD('ON') + ' ' +
    277280                style.SQL_TABLE(qn(model._meta.db_table)) + ' ' +
    278281                "(%s)" % style.SQL_FIELD(qn(f.column)) +
Back to Top