diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-05-07 13:04:29 -0700 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-05-07 13:05:32 -0700 |
| commit | f67433e74b06bbeb9b6bba0a9db5fb33512bdb43 (patch) | |
| tree | 2e4323def6d6c0fb16dca4e7f2b4b878553590bd | |
| parent | af06203cead2968f4d58a718100dedc0faa7c619 (diff) | |
[1.7.x] Fixed #22563: Better error message when trying to change AUTH_USER_MODEL
You're not allowed to do this after you've made migrations; see ticket
for more details.
| -rw-r--r-- | django/db/migrations/state.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py index a5ea1cf37c..90e0b51b1e 100644 --- a/django/db/migrations/state.py +++ b/django/db/migrations/state.py @@ -5,6 +5,7 @@ from django.apps.registry import Apps, apps as global_apps 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 @@ class ProjectState(object): try: 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.Book.author: 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, )) else: do_pending_lookups(model) |
