#18392: Make MySQL backend default to utf8mb4 encoding
-------------------------------------+-------------------------------------
     Reporter:  EmilStenstrom        |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  1.4
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  utf8mb4 mysql        |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Kelly Campbell):

 As a workaround, I came up with this monkey patch that limits the index
 size. We put this in our migrations/__init__.py:

 {{{
 from django.db.models.fields import CharField

 def _create_index_sql(self, model, fields, suffix="", sql=None):
     """
     Return the SQL statement to create the index for one or several
 fields.
     `sql` can be specified if the syntax differs from the standard (GIS
     indexes, ...).
     """
     tablespace_sql = self._get_index_tablespace_sql(model, fields)
     idx_columns = []
     for field in fields:
         c = field.column
         if isinstance(field, CharField):
             if field.max_length > 255:
                 idx_columns.append(self.quote_name(c) + '(255)')
             else:
                 idx_columns.append(self.quote_name(c))
         else:
             idx_columns.append(self.quote_name(c))
     columns = [field.column for field in fields]
     sql_create_index = sql or self.sql_create_index
     return sql_create_index % {
         "table": self.quote_name(model._meta.db_table),
         "name": self.quote_name(self._create_index_name(model, columns,
 suffix=suffix)),
         "using": "",
         "columns": ", ".join(column for column in idx_columns),
         "extra": tablespace_sql,
     }


 from django.db.backends.mysql.schema import DatabaseSchemaEditor
 DatabaseSchemaEditor._create_index_sql = _create_index_sql

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18392#comment:45>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.47db1f449d57502b1ed391d02bde890d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to