title: Django: How to fix UUID ValueError('badly formed hexadecimal UUID string')?
body: <p>I am using Python 3.8 and Django 3.0.</p>
  <p>Models.py</p>
  <pre><code>class CustomeUser(AbstractUser):
  id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  ...
  
  class ActivationCode(models.Model):
  Code = models.CharField(max_length=30, null=False, unique=True)
  ForUser = models.ForeignKey(CustomUser, null=True, blank=True, on_delete=models.CASCADE)
  ...
  </code></pre>
  <p>Code:</p>
  <pre><code>jj = {'app_id': '100',
   'color': 'blue',
   'os_type': 'MacOS',
   'time': '1596397345',
   'regKey': 'dJbeetbQ',
   'os_version': '10.15.6',
   'place_id': '20190228-3',
   'version': '2.0.0.8',
   'guid': '10614ba9b54f909a715ed518cc39741811369a11',
   'randomString': '3808651424'}
  
  regKey = jj[&quot;regKey&quot;]
  record = ActivationCode.objects.get(Code=regKey)
  </code></pre>
  <p>will get exception when regKey matches a user record. If the ForUser field is null, it will go through.</p>
  <p>What's the problem here?</p>
  <p>Full trace back:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\Ken\anaconda3\lib\site-packages\IPython\core\interactiveshell.py&quot;, line 3331, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File &quot;&lt;ipython-input-59-b3b355ae1522&gt;&quot;, line 1, in &lt;module&gt;
      ActivationCode.objects.get(Code=regKey)
    File &quot;C:\Users\Ken\anaconda3\lib\site-packages\django\db\models\manager.py&quot;, line 82, in manager_method
      return getattr(self.get_queryset(), name)(*args, **kwargs)
    File &quot;C:\Users\Ken\anaconda3\lib\site-packages\django\db\models\query.py&quot;, line 411, in get
      num = len(clone)
    File &quot;C:\Users\Ken\anaconda3\lib\site-packages\django\db\models\query.py&quot;, line 258, in __len__
      self._fetch_all()
    File &quot;C:\Users\Ken\anaconda3\lib\site-packages\django\db\models\query.py&quot;, line 1261, in _fetch_all
      self._result_cache = list(self._iterable_class(self))
    File &quot;C:\Users\Ken\anaconda3\lib\site-packages\django\db\models\query.py&quot;, line 74, in __iter__
      for row in compiler.results_iter(results):
    File &quot;C:\Users\Ken\anaconda3\lib\site-packages\django\db\models\sql\compiler.py&quot;, line 1088, in apply_converters
      value = converter(value, expression, connection)
    File &quot;C:\Users\Ken\anaconda3\lib\site-packages\django\db\backends\mysql\operations.py&quot;, line 270, in convert_uuidfield_value
      value = uuid.UUID(value)
    File &quot;C:\Users\Ken\anaconda3\lib\uuid.py&quot;, line 160, in __init__
      raise ValueError('badly formed hexadecimal UUID string')
  ValueError: badly formed hexadecimal UUID string
  </code></pre>