title: Django not finding custom user model in settings when migrating
body: <p>I've created a custom <code>User</code> model in models.py:</p>
  
  <pre><code>class User(AbstractUser):
      pass
  </code></pre>
  
  <p>Then, I've set <code>AUTH_USER_MODEL</code> to that model, in settings.py:</p>
  
  <pre><code>AUTH_USER_MODEL = 'workoutcal.User'
  </code></pre>
  
  <p>workoutcal is included in <code>INSTALLED_APPS</code>:</p>
  
  <pre><code>INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'workoutcal',
      'rest_framework',
      'rest_framework_mongoengine',
  ]
  </code></pre>
  
  <p>And I've included this in admin.py:</p>
  
  <pre><code>admin.site.register(User, UserAdmin)
  </code></pre>
  
  <p>Then, I've ran <code>makemigrations</code> and <code>migrate</code>, and on the latter, I get this long error traceback:</p>
  
  <pre><code>(workout) sahands-mbp:workout sahandzarrinkoub$ python manage.py migrate
  Operations to perform:
    Apply all migrations: admin, auth, contenttypes, sessions, workoutcal
  Running migrations:
    Applying admin.0001_initial...Traceback (most recent call last):
    File "manage.py", line 22, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
      utility.execute()
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
      output = self.handle(*args, **options)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
      fake_initial=fake_initial,
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/migrations/executor.py", line 115, in migrate
      state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
      state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
      state = migration.apply(state, schema_editor)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply
      operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 97, in database_forwards
      schema_editor.create_model(model)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 254, in create_model
      definition, extra_params = self.column_sql(model, field)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 144, in column_sql
      db_params = field.db_parameters(connection=self.connection)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/models/fields/related.py", line 994, in db_parameters
      return {"type": self.db_type(connection), "check": self.db_check(connection)}
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/models/fields/related.py", line 991, in db_type
      return self.target_field.rel_db_type(connection=connection)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/models/fields/related.py", line 909, in target_field
      return self.foreign_related_fields[0]
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/models/fields/related.py", line 653, in foreign_related_fields
      return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/models/fields/related.py", line 640, in related_fields
      self._related_fields = self.resolve_related_fields()
    File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/models/fields/related.py", line 625, in resolve_related_fields
      raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
  ValueError: Related model 'workoutcal.User' cannot be resolved
  </code></pre>
  
  <p>It seems to me like the error stems from the admin.0001_initial migration. When I look into the python file of that migration, I find this:</p>
  
  <pre><code># -*- coding: utf-8 -*-
  from __future__ import unicode_literals
  
  import django.contrib.admin.models
  from django.conf import settings
  from django.db import migrations, models
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          migrations.swappable_dependency(settings.AUTH_USER_MODEL),
          ('contenttypes', '__first__'),
      ]
  
      operations = [
          migrations.CreateModel(
              name='LogEntry',
              fields=[
                  ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                  ('action_time', models.DateTimeField(auto_now=True, verbose_name='action time')),
                  ('object_id', models.TextField(null=True, verbose_name='object id', blank=True)),
                  ('object_repr', models.CharField(max_length=200, verbose_name='object repr')),
                  ('action_flag', models.PositiveSmallIntegerField(verbose_name='action flag')),
                  ('change_message', models.TextField(verbose_name='change message', blank=True)),
                  ('content_type', models.ForeignKey(
                      to_field='id',
                      on_delete=models.SET_NULL,
                      blank=True, null=True,
                      to='contenttypes.ContentType',
                      verbose_name='content type',
                  )),
                  ('user', models.ForeignKey(
                      to=settings.AUTH_USER_MODEL,
                      on_delete=models.CASCADE,
                      verbose_name='user',
                  )),
              ],
              options={
                  'ordering': ('-action_time',),
                  'db_table': 'django_admin_log',
                  'verbose_name': 'log entry',
                  'verbose_name_plural': 'log entries',
              },
              bases=(models.Model,),
              managers=[
                  ('objects', django.contrib.admin.models.LogEntryManager()),
              ],
          ),
      ]
  </code></pre>
  
  <p>What is the reason for my error, and how do I solve it?</p>
  
  <p>EDIT: Alasdair asked whether or not my workoutcal app has migrations. It does. The migrations-folder contains three python-files: </p>
  
  <p><strong>__init__.py</strong></p>
  
  <pre><code># empty
  </code></pre>
  
  <p><strong>0001_initial.py</strong></p>
  
  <pre><code># -*- coding: utf-8 -*-
  # Generated by Django 1.11.5 on 2017-09-11 17:20
  from __future__ import unicode_literals
  
  from django.db import migrations, models
  import django.db.models.deletion
  
  
  class Migration(migrations.Migration):
  
      initial = True
  
      dependencies = [
      ]
  
      operations = [
          migrations.CreateModel(
              name='Person',
              fields=[
                  ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                  ('name', models.CharField(max_length=200)),
              ],
          ),
          migrations.CreateModel(
              name='Workout',
              fields=[
                  ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                  ('date', models.DateTimeField(verbose_name='workout date')),
                  ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workoutcal.Person')),
              ],
          ),
      ]
  </code></pre>
  
  <p><strong>0002_auto_20171212_1445</strong></p>
  
  <pre><code># -*- coding: utf-8 -*-
  # Generated by Django 1.11.5 on 2017-12-12 14:45
  from __future__ import unicode_literals
  
  import django.contrib.auth.models
  import django.contrib.auth.validators
  from django.db import migrations, models
  import django.utils.timezone
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('auth', '0008_alter_user_username_max_length'),
          ('workoutcal', '0001_initial'),
      ]
  
      operations = [
          migrations.CreateModel(
              name='User',
              fields=[
                  ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                  ('password', models.CharField(max_length=128, verbose_name='password')),
                  ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                  ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                  ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
                  ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
                  ('last_name', models.CharField(blank=True, max_length=30, verbose_name='last name')),
                  ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
                  ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
                  ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
                  ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
                  ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
                  ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
              ],
              options={
                  'verbose_name': 'user',
                  'verbose_name_plural': 'users',
                  'abstract': False,
              },
              managers=[
                  ('objects', django.contrib.auth.models.UserManager()),
              ],
          ),
          migrations.RemoveField(
              model_name='workout',
              name='person',
          ),
          migrations.DeleteModel(
              name='Person',
          ),
          migrations.DeleteModel(
              name='Workout',
          ),
      ]
  </code></pre>