title: On Django with a MySQL backend, "Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='"
body: <p>In a Python 2 Django app, I'm defining a string with a 'money with wings' emoji:</p>
  
  <pre><code># -*- coding: UTF-8 -*-
  MESSAGE = "Stash some cash "
  </code></pre>
  
  <p>This passes the <code>pylint</code> linter fine.</p>
  
  <p>However, I also have a model <code>Message</code> with a <code>content</code> field, and if I try to write to there, I get an error message:</p>
  
  <pre><code>Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='
  </code></pre>
  
  <p>Below is the full stack trace. How can I fix this? Since <code>utf8mb4_general_ci</code> is MySQL-specific, I suppose that the encoding the database is currently in, and <code>utf8_general_ci</code> is the encoding that I'm defining my string to be. How can I define my string to be in <code>utf8mb4_general_ci</code> instead of <code>utf8_general_ci</code>? </p>
  
  <pre><code>/app/venmo_platform/current/venmo/communication/services/notification_service.pyc in get_message_for_notification(message_content)
       99 
      100 def get_message_for_notification(message_content):
  --&gt; 101     message, _ = Message.objects.get_or_create(content=message_content)
      102     return message
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/models/manager.pyc in manager_method(self, *args, **kwargs)
      125         def create_method(name, method):
      126             def manager_method(self, *args, **kwargs):
  --&gt; 127                 return getattr(self.get_queryset(), name)(*args, **kwargs)
      128             manager_method.__name__ = method.__name__
      129             manager_method.__doc__ = method.__doc__
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/models/query.pyc in get_or_create(self, defaults, **kwargs)
      403         self._for_write = True
      404         try:
  --&gt; 405             return self.get(**lookup), False
      406         except self.model.DoesNotExist:
      407             return self._create_object_from_params(lookup, params)
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/models/query.pyc in get(self, *args, **kwargs)
      326         if self.query.can_filter():
      327             clone = clone.order_by()
  --&gt; 328         num = len(clone)
      329         if num == 1:
      330             return clone._result_cache[0]
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/models/query.pyc in __len__(self)
      142 
      143     def __len__(self):
  --&gt; 144         self._fetch_all()
      145         return len(self._result_cache)
      146 
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/models/query.pyc in _fetch_all(self)
      963     def _fetch_all(self):
      964         if self._result_cache is None:
  --&gt; 965             self._result_cache = list(self.iterator())
      966         if self._prefetch_related_lookups and not self._prefetch_done:
      967             self._prefetch_related_objects()
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/models/query.pyc in iterator(self)
      236         # Execute the query. This will also fill compiler.select, klass_info,
      237         # and annotations.
  --&gt; 238         results = compiler.execute_sql()
      239         select, klass_info, annotation_col_map = (compiler.select, compiler.klass_info,
      240                                                   compiler.annotation_col_map)
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/models/sql/compiler.pyc in execute_sql(self, result_type)
      838         cursor = self.connection.cursor()
      839         try:
  --&gt; 840             cursor.execute(sql, params)
      841         except Exception:
      842             cursor.close()
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/backends/utils.pyc in execute(self, sql, params)
       77         start = time()
       78         try:
  ---&gt; 79             return super(CursorDebugWrapper, self).execute(sql, params)
       80         finally:
       81             stop = time()
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/backends/utils.pyc in execute(self, sql, params)
       62                 return self.cursor.execute(sql)
       63             else:
  ---&gt; 64                 return self.cursor.execute(sql, params)
       65 
       66     def executemany(self, sql, param_list):
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/utils.pyc in __exit__(self, exc_type, exc_value, traceback)
       96                 if dj_exc_type not in (DataError, IntegrityError):
       97                     self.wrapper.errors_occurred = True
  ---&gt; 98                 six.reraise(dj_exc_type, dj_exc_value, traceback)
       99 
      100     def __call__(self, func):
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/backends/utils.pyc in execute(self, sql, params)
       62                 return self.cursor.execute(sql)
       63             else:
  ---&gt; 64                 return self.cursor.execute(sql, params)
       65 
       66     def executemany(self, sql, param_list):
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/django/db/backends/mysql/base.pyc in execute(self, query, args)
      122         try:
      123             # args is None means no string interpolation
  --&gt; 124             return self.cursor.execute(query, args)
      125         except Database.OperationalError as e:
      126             # Map some error codes to IntegrityError, since they seem to be
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/MySQLdb/cursors.pyc in execute(self, query, args)
      248         except Exception:
      249             exc, value = sys.exc_info()[:2]
  --&gt; 250             self.errorhandler(self, exc, value)
      251         self._executed = query
      252         if not self._defer_warnings:
  
  /app/shared/virtualenvs/venmo_platform27/local/lib/python2.7/site-packages/MySQLdb/connections.pyc in defaulterrorhandler(***failed resolving arguments***)
       48     del connection
       49     if isinstance(errorvalue, BaseException):
  ---&gt; 50         raise errorvalue
       51     if errorclass is not None:
       52         raise errorclass(errorvalue)
  
  OperationalError: (1267, "Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='")
  </code></pre>