title: Django Foreign Key to_field
body: <p>I have 2 models <strong>CustomUser</strong> and <strong>Magazine</strong> with random/unique slug fields. Now I want to create a third model (Article) with foreign keys to the slug field:</p>
  
  <pre><code>class CustomUser(AbstractBaseUser):
      slug = RandomSlugField(length=6, unique=True)
      ...
  
  class Magazine(models.Model):
      slug = RandomSlugField(length=6, unique=True)
      name = models.CharField()
  
  class Article(models.Model):
      magazine = models.ForeignKey(Magazine, to_field='slug')
      author = models.ForeignKey(settings.AUTH_USER_MODEL, to_field='slug')
  </code></pre>
  
  <p>But when I migrate the database to create the Article model, I get the following error:</p>
  
  <pre><code>django.core.exceptions.FieldDoesNotExist: CustomUser has no field named 'slug'
  </code></pre>
  
  <p>But CustomUser obviously has a field named 'slug'.</p>
  
  <p>And for the Magazine model I don't get this error. 
  Has anyone an idea what is going wrong?</p>
  
  <p>I use this package for the slug field:
  <a href="https://github.com/mkrjhnsn/django-randomslugfield" rel="nofollow noreferrer">https://github.com/mkrjhnsn/django-randomslugfield</a> </p>
  
  <p>EDIT:
  Here is the full CustomUser model:</p>
  
  <pre><code>class CustomUser(AbstractBaseUser, PermissionsMixin):
      slug = RandomSlugField(length=6, exclude_upper=True)
      username = models.CharField(
          _('username'), max_length=30,
          help_text=_('Required. 30 characters or fewer.'
                  'Letters, digits and '
                  '@/./+/-/_ only.'),
          validators=[
              validators.RegexValidator(r'^[\w.@+-]+$',
                                    _('Enter a valid username.'), 'invalid')
          ])
      first_name = models.CharField(_('first name'), max_length=30, blank=True)
      last_name = models.CharField(_('last name'), max_length=30, blank=True)
  
      # email is our unique field for authentication
      email = models.EmailField(_('email address'), unique=True)
  
      is_staff = models.BooleanField(
          _('staff status'), default=False,
          help_text=_('Designates whether the user can log '
                      'into this admin site.')
          )
      is_active = models.BooleanField(
          _('active'),
          default=True,
          help_text=_('Designates whether this user should be treated as '
                      'active. Unselect this instead of deleting accounts.')
          )
      date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
  
      objects = UserManager()
  
      profile = models.OneToOneField('UserProfile', blank=True, null=True,
                                 related_name='user_profile')
  
      image = models.ImageField(default='images/noimage.jpg',
                            upload_to=settings.PROFILE_IMAGE_PATH,
                            max_length=255)
  
      USERNAME_FIELD = 'email'
      REQUIRED_FIELDS = ['username']
  </code></pre>