'migrate' triggers lazy reference error when changing custom user model name

1,785 views
Skip to first unread message

Johan Cockx

unread,
Dec 7, 2016, 7:18:55 AM12/7/16
to Django users
I am running  Django 1.10.4 with Python 3.4.3, learning about Django.

I created a custom user model 'MyUser' copied from the Django docs at https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#substituting-a-custom-user-model;  this works fine.

Then I renamed the model from 'MyUser' to 'TheUser', updating models.py, admin.py and settings.py and succesfully ran 'makemigrations'.  Then,  when I run 'migrate',  I get the traceback below.

If I temporarily comment the AUTH_USER_MODEL setting, makemigrations works fine, but as soon as I uncomment the AUTH_USER_MODEL setting again,  both 'makemigrations' and 'migrate' fail with the same error and a similar traceback.
I did not do any additional changes to the model, so makemigrations and migrate should actually not do anything at this point.

Is this a bug?

I have attached a complete project that can be used to reproduce the problem.


$ python manage.py makemigrations
Did you rename the auth_by_email.MyUser model to TheUser? [y/N] y
Migrations for 'admin':
  /home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/contrib/admin/migrations/0003_auto_20161207_1018.py:
    - Alter field user on logentry
Migrations for 'auth_by_email':
  auth_by_email/migrations/0003_auto_20161207_1018.py:
    - Rename model MyUser to TheUser

$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, auth_by_email, contenttypes, sessions
Traceback (most recent call last):
  File "/home/johan/work/backend/manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 164, in handle
    pre_migrate_apps = pre_migrate_state.apps
  File "/home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/db/migrations/state.py", line 176, in apps
    return StateApps(self.real_apps, self.models)
  File "/home/johan/Seafile/main/sikando/Projects/doclr/env/lib/python3.4/site-packages/django/db/migrations/state.py", line 249, in __init__
    raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'auth_by_email.theuser', but app 'auth_by_email' doesn't provide model 'theuser'.
backend.tgz

Олег Ямников

unread,
Apr 7, 2017, 1:40:20 PM4/7/17
to Django users
Hello!

I'm having the same problem right now. Have you found any solution? That would be very helpful to me.

Thank you.
Reply all
Reply to author
Forward
0 new messages