title: ValueError: badly formed hexadecimal UUID string
body: <p>In my system I'm trying to auto generate a unique random string for each users to be passed later on in the URL as the reference to that account and I recently read about the UUID in django models. And this is how my model looks like:</p>
  <pre><code>class User(AbstractBaseUser, PermissionsMixin):
      card_number = models.CharField(max_length=20, unique=True)
      first_name = models.CharField(max_length=150)
      middle_name = models.CharField(max_length=150)
      last_name = models.CharField(max_length=150)
      address = models.CharField(max_length=200)
      account_code = models.UUIDField(max_length=200, default=uuid.uuid4(), editable=False)
  </code></pre>
  <p>And I ran into an error when start creating superuser in the terminal:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\viaje\manage.py&quot;, line 22, in &lt;module&gt;
      main()
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\viaje\manage.py&quot;, line 18, in main
      execute_from_command_line(sys.argv)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\core\management\__init__.py&quot;, line 401, in execute_from_command_line
      utility.execute()
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\core\management\__init__.py&quot;, line 395, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\core\management\base.py&quot;, line 330, in run_from_argv
      self.execute(*args, **cmd_options)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py&quot;, line 79, in execute
      return super().execute(*args, **options)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\core\management\base.py&quot;, line 371, in execute
      output = self.handle(*args, **options)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py&quot;, line 113, in handle
      error_msg = self._validate_username(username, verbose_field_name, database)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py&quot;, line 234, in _validate_username
      self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\contrib\auth\base_user.py&quot;, line 45, in get_by_natural_key
      return self.get(**{self.model.USERNAME_FIELD: username})
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\db\models\manager.py&quot;, line 85, in manager_method
      return getattr(self.get_queryset(), name)(*args, **kwargs)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\db\models\query.py&quot;, line 425, in get
      num = len(clone)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\db\models\query.py&quot;, line 269, in __len__
      self._fetch_all()
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\db\models\query.py&quot;, line 1308, in _fetch_all
      self._result_cache = list(self._iterable_class(self))
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\db\models\query.py&quot;, line 70, in __iter__
      for row in compiler.results_iter(results):
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\db\models\sql\compiler.py&quot;, line 1100, in apply_converters
      value = converter(value, expression, connection)
    File &quot;C:\Users\User\PycharmProjects\ViajeroProject\venv\lib\site-packages\django\db\backends\sqlite3\operations.py&quot;, line 318, in convert_uuidfield_value
      value = uuid.UUID(value)
    File &quot;C:\Users\User\AppData\Local\Programs\Python\Python39\lib\uuid.py&quot;, line 177, in __init__
      raise ValueError('badly formed hexadecimal UUID string')
  ValueError: badly formed hexadecimal UUID string
  </code></pre>
  <p>How should I address this or is this practice not advisable where I auto generate a unique random string as reference for the user in the URL? Note that users still have their PKs which different from the account_code.</p>
  <p>Thank you!</p>