summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2012-11-24 13:43:20 +0800
committerRussell Keith-Magee <russell@keith-magee.com>2012-11-24 14:26:50 +0800
commit3fd8458fb3a30ea9fc6b3e7c08ff2d66a63e5067 (patch)
tree44e51d51579cdd0d46ce909d6821c0ce8bf695e4 /django/core
parent158a0332bfef38277ba0a6f7a89815624a7d0ea2 (diff)
[1.5.x] Fixed #19806 -- Ensure that content types and permissions aren't created for swapped models.
Thanks to rizumu for the report. Backport of c8985a8a7317042a641e870cb75b3005cc5d67b1.
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management/validation.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/django/core/management/validation.py b/django/core/management/validation.py
index 32e7181dab..af15752f0f 100644
--- a/django/core/management/validation.py
+++ b/django/core/management/validation.py
@@ -35,7 +35,10 @@ def get_validation_errors(outfile, app=None):
for (app_name, error) in get_app_errors().items():
e.add(app_name, error)
- for cls in models.get_models(app):
+ inc = set(models.get_models(app, include_swapped=True))
+ no_inc = set(models.get_models(app))
+
+ for cls in models.get_models(app, include_swapped=True):
opts = cls._meta
# Check swappable attribute.
@@ -138,16 +141,17 @@ def get_validation_errors(outfile, app=None):
# fields, m2m fields, m2m related objects or related objects
if f.rel:
if f.rel.to not in models.get_models():
- e.add(opts, "'%s' has a relation with model %s, which has either not been installed or is abstract." % (f.name, f.rel.to))
+ # If the related model is swapped, provide a hint;
+ # otherwise, the model just hasn't been installed.
+ if not isinstance(f.rel.to, six.string_types) and f.rel.to._meta.swapped:
+ e.add(opts, "'%s' defines a relation with the model '%s.%s', which has been swapped out. Update the relation to point at settings.%s." % (f.name, f.rel.to._meta.app_label, f.rel.to._meta.object_name, f.rel.to._meta.swappable))
+ else:
+ e.add(opts, "'%s' has a relation with model %s, which has either not been installed or is abstract." % (f.name, f.rel.to))
# it is a string and we could not find the model it refers to
# so skip the next section
if isinstance(f.rel.to, six.string_types):
continue
- # Make sure the model we're related hasn't been swapped out
- if f.rel.to._meta.swapped:
- e.add(opts, "'%s' defines a relation with the model '%s.%s', which has been swapped out. Update the relation to point at settings.%s." % (f.name, f.rel.to._meta.app_label, f.rel.to._meta.object_name, f.rel.to._meta.swappable))
-
# Make sure the related field specified by a ForeignKey is unique
if not f.rel.to._meta.get_field(f.rel.field_name).unique:
e.add(opts, "Field '%s' under model '%s' must have a unique=True constraint." % (f.rel.field_name, f.rel.to.__name__))
@@ -184,16 +188,18 @@ def get_validation_errors(outfile, app=None):
# existing fields, m2m fields, m2m related objects or related
# objects
if f.rel.to not in models.get_models():
- e.add(opts, "'%s' has an m2m relation with model %s, which has either not been installed or is abstract." % (f.name, f.rel.to))
+ # If the related model is swapped, provide a hint;
+ # otherwise, the model just hasn't been installed.
+ if not isinstance(f.rel.to, six.string_types) and f.rel.to._meta.swapped:
+ e.add(opts, "'%s' defines a relation with the model '%s.%s', which has been swapped out. Update the relation to point at settings.%s." % (f.name, f.rel.to._meta.app_label, f.rel.to._meta.object_name, f.rel.to._meta.swappable))
+ else:
+ e.add(opts, "'%s' has an m2m relation with model %s, which has either not been installed or is abstract." % (f.name, f.rel.to))
+
# it is a string and we could not find the model it refers to
# so skip the next section
if isinstance(f.rel.to, six.string_types):
continue
- # Make sure the model we're related hasn't been swapped out
- if f.rel.to._meta.swapped:
- e.add(opts, "'%s' defines a relation with the model '%s.%s', which has been swapped out. Update the relation to point at settings.%s." % (f.name, f.rel.to._meta.app_label, f.rel.to._meta.object_name, f.rel.to._meta.swappable))
-
# Check that the field is not set to unique. ManyToManyFields do not support unique.
if f.unique:
e.add(opts, "ManyToManyFields cannot be unique. Remove the unique argument on '%s'." % f.name)