Exception when migrating custom User in Django
<p>I need to create a custom User for my app and followed exactly the <a href="https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#a-full-example" rel="nofollow">example</a> from the documentation with the <code>AUTH_USER_MODEL = 'core.MyUser'</code> in my <code>settings.py</code>. However, when I make a new database, delete all the migrations folders and run the <code>python manage.py migrate</code> again, it gives me the exception like this </p>

<pre><code>  File "manage.py", line 22, in &lt;module&gt;
    execute_from_command_line(sys.argv)
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 173, in handle
    migration_name=self.migration_name,
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 47, in changes
    changes = self._detect_changes(convert_apps, graph)
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 132, in _detect_changes
    self.old_apps = self.from_state.concrete_apps
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/db/migrations/state.py", line 180, in concrete_apps
    self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/db/migrations/state.py", line 242, in __init__
    self.render_multiple(list(models.values()) + self.real_models)
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/db/migrations/state.py", line 277, in render_multiple
    model.render(self)
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/db/migrations/state.py", line 559, in render
    body,
  File "/Users/bubuzzz/Projects/python/apps/lib/python2.7/site-packages/django/db/models/base.py", line 153, in __new__
    raise TypeError("%s cannot proxy the swapped model '%s'." % (name, base_meta.swapped))
TypeError: Customer cannot proxy the swapped model 'core.MyUser'.
</code></pre>

<p>I am not sure why there is a migrations script for the <code>customer</code> there, since in my app, I used to have the <code>Customer</code> model as well, though I deleted it already. </p>

<p>Then, I created a new django project to test and try to run the migration. Surprisingly, I also see those customer migration steps, but it run successfully. </p>

<pre><code>  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_customer... OK
  Applying auth.0010_delete_customer... OK
  Applying sessions.0001_initial... OK
</code></pre>

<p>In short, how can I create the custom User in Django 1.10 ? Example code can be viewed in here <a href="https://github.com/bubuzzz/django-customer-swap-exception" rel="nofollow">https://github.com/bubuzzz/django-customer-swap-exception</a></p>

<p>Mehdi Pourfar's answer is correct.If you want to know more details </p>

<blockquote>
  <p>By running makemigrations, youâre telling Django that youâve made some changes to your models (in this case, youâve made new ones) and that youâd like the changes to be stored as a migration.</p>
  
  <p>Migrations are how Django stores changes to your models (and thus your database schema) - theyâre just files on disk. You can read the migration for your new model if you like; itâs the file polls/migrations/0001_initial.py. Donât worry, youâre not expected to read them every time Django makes one, but theyâre designed to be human-editable in case you want to manually tweak how Django changes things.</p>
</blockquote>

<p>Tell django which app you want to make migrations all fix your problem.It will auto create a folder call migrations keep your model's record.</p>

<pre><code>python manage.py makemigrations core
</code></pre>

python django