title: Django student here: I'm I getting a ValueError when creating a superuser using a custom made User class
body: <p>I am working on a project that requires one to only create an account if their other details such as username are already in the database.
  For this I created a custom user class named Account and linked the username field through a OneToOne relationship to the Reg No in the Student class.
  I manually prepopulated the database with a single record so as to be able to create a superuser, because the creation of an account would require an existing Student record. <strong>But I am getting a value error on the terminal like so:</strong></p>
  <pre><code>(djangoenv) myMachine:~/Django9/eschool$ python3 manage.py createsuperuser
  Email: ********@**.me
  Username (Student.School_ID): 1
  Password: 
  Password (again): 
  Traceback (most recent call last):
    File &quot;/home/biketi21/Django9/eschool/manage.py&quot;, line 22, in &lt;module&gt;
      main()
    File &quot;/home/biketi21/Django9/eschool/manage.py&quot;, line 18, in main
      execute_from_command_line(sys.argv)
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/core/management/__init__.py&quot;, line 419, in execute_from_command_line
      utility.execute()
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/core/management/__init__.py&quot;, line 413, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/core/management/base.py&quot;, line 354, in run_from_argv
      self.execute(*args, **cmd_options)
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/contrib/auth/management/commands/createsuperuser.py&quot;, line 79, in execute
      return super().execute(*args, **options)
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/core/management/base.py&quot;, line 398, in execute
      output = self.handle(*args, **options)
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/contrib/auth/management/commands/createsuperuser.py&quot;, line 157, in handle
      validate_password(password2, self.UserModel(**fake_user_data))
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/db/models/base.py&quot;, line 485, in __init__
      _setattr(self, field.name, rel_obj)
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/db/models/fields/related_descriptors.py&quot;, line 310, in __set__
      super().__set__(instance, value)
    File &quot;/home/biketi21/anaconda3/envs/djangoenv/lib/python3.9/site-packages/django/db/models/fields/related_descriptors.py&quot;, line 215, in __set__
      raise ValueError(
  ValueError: Cannot assign &quot;1&quot;: &quot;Account.username&quot; must be a &quot;Student&quot; instance.
  </code></pre>
  <p><strong>Below is my Models.py:</strong>
  I'm using MySQL Database as the backend.</p>
  <pre><code>from django.db import models
  from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
  
  
  # Create your models here.
  
  class Student(models.Model):
      FirstName = models.CharField(max_length=50)
      Surname = models.CharField(max_length=50)
      Reg_No = models.CharField(max_length=11, unique=True)
      National_ID = models.IntegerField(unique=True)
      School_ID = models.AutoField(primary_key=True)
      County = models.CharField(max_length=20)
      Sub_County = models.CharField(max_length=50)
      Course_Title = models.ForeignKey(&quot;Course&quot;, on_delete=models.CASCADE)
      Admission_Date = models.DateField(auto_now=True)
  
      def __str__(self):
          return str(self.Reg_No)
  
  class Course(models.Model):
      Course_Title = models.CharField(max_length=100)
      Course_ID = models.CharField(max_length=10)
      Number_of_Semesters = models.IntegerField()
      Total_Cost_of_Course = models.IntegerField()
  
      def __str__(self):
          return str(self.Course_ID)
  
  
  
  class MyAccountManager(BaseUserManager):
      def create_user(self, email, username, password=None):
          if not email:
              raise ValueError('Users must have an email address.')
          if not username:
              raise ValueError('Users must have a username.')
  
          user = self.model(
                  email=self.normalize_email(email),
                  username=username,
              )
  
          user.set_password(password)
          user.save(using=self._db)
          return user
  
      def create_superuser(self, email, username, password):
          user = self.create_user(
                  email=self.normalize_email(email),
                  password=password,
                  username=username,
              )
          user.is_admin     = True
          user.is_staff     = True
          user.is_superuser = True
          user.save(using=self._db)
          return user
  
  
  
  class Account(AbstractBaseUser):
      email           = models.EmailField(verbose_name='email', max_length=60, unique=True)
      username        = models.OneToOneField(Student, unique=True, on_delete=models.CASCADE)
      date_joined     = models.DateTimeField(verbose_name='date joined', auto_now_add=True)
      last_login      = models.DateTimeField(verbose_name='last login', auto_now=True)
      is_admin        = models.BooleanField(default=False)
      is_active       = models.BooleanField(default=True)
      is_staff        = models.BooleanField(default=False)
      is_superuser    = models.BooleanField(default=False)
  
      USERNAME_FIELD  = 'email'
      REQUIRED_FIELDS = ['username']
  
      objects = MyAccountManager()
  
      def __str__(self):
          return self.username
  
      def has_perm(self, perm, obj=None):
          return self.is_admin
  
      def has_module_perms(self, app_label):
          return True
  </code></pre>
  <p>Any help in solving this problem is appreciated.</p>