Skip to content
Browse files

[1.7.x] Fixed #22563: Better error message when trying to change AUTH…


You're not allowed to do this after you've made migrations; see ticket
for more details.
  • Loading branch information...
1 parent af06203 commit f67433e74b06bbeb9b6bba0a9db5fb33512bdb43 @andrewgodwin andrewgodwin committed
Showing with 14 additions and 3 deletions.
  1. +14 −3 django/db/migrations/
17 django/db/migrations/
@@ -5,6 +5,7 @@
from django.db import models
from django.db.models.options import DEFAULT_NAMES, normalize_together
from django.db.models.fields.related import do_pending_lookups
+from django.conf import settings
from django.utils import six
from django.utils.encoding import force_text
from django.utils.module_loading import import_string
@@ -74,13 +75,23 @@ def render(self, include_real=None):
model = self.apps.get_model(lookup_model[0], lookup_model[1])
except LookupError:
+ # If the lookup failed to something that looks like AUTH_USER_MODEL,
+ # give a better error message about how you can't change it (#22563)
+ extra_message = ""
+ if "%s.%s" % (lookup_model[0], lookup_model[1]) == settings.AUTH_USER_MODEL:
+ extra_message = (
+ "\nThe missing model matches AUTH_USER_MODEL; if you've changed the value of this" +
+ "\nsetting after making a migration, be aware that this is not supported. If you" +
+ "\nchange AUTH_USER_MODEL you must delete and recreate migrations for its app."
+ )
# Raise an error with a best-effort helpful message
# (only for the first issue). Error message should look like:
# "ValueError: Lookup failed for model referenced by
# field migrations.Author"
- raise ValueError("Lookup failed for model referenced by field {field}: {model[0]}.{model[1]}".format(
- field=operations[0][1],
- model=lookup_model
+ raise ValueError("Lookup failed for model referenced by field {field}: {model[0]}.{model[1]}{extra_message}".format(
+ field = operations[0][1],
+ model = lookup_model,
+ extra_message = extra_message,

0 comments on commit f67433e

Please sign in to comment.
Something went wrong with that request. Please try again.