Ticket #2495: hack-mysql-TextField-index.patch

File hack-mysql-TextField-index.patch, 1.3 KB (added by mizatservercave, 16 years ago)

Preliminary hack against Django 1.0.2final

  • django/db/backends/mysql/creation.py

    diff -r 7c329cb87649 django/db/backends/mysql/creation.py
     
    6363                field.rel.to._meta.db_table, field.rel.to._meta.pk.column)
    6464            ]
    6565        return table_output, deferred
    66        
    67  No newline at end of file
     66       
     67    def sql_indexes_for_field(self, model, f, style):
     68        """ Hack the return-value of
     69            BaseDatabaseCreation.sql_indexes_for_field() to add a
     70            prefix length to the TextField which is currently
     71            represented by MySQL's 'longtext' type -- which requires
     72            a prefix-length parameter in order to install an index.
     73
     74            All other types are passed unchanged.
     75        """
     76
     77        qn = self.connection.ops.quote_name
     78        out = super(DatabaseCreation, self).sql_indexes_for_field(model, f, style)
     79
     80        if not out or not f.db_type() == self.data_types['TextField']:
     81            return out
     82
     83        field = "%s" % style.SQL_FIELD(qn(f.column))
     84
     85        newout = []
     86        for item in out:
     87            # 1000-byte prefix length maximum (apparently), else warning
     88            newout = [item.replace(field, "%s(1000)" % field)]
     89
     90        return newout
     91
Back to Top