diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index 45fbf8b730..c68379b6ab 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -67,7 +67,7 @@ class GenericForeignKey(six.with_metaclass(RenameGenericForeignKeyMethods)): 'Field names must not end with an underscore.', hint=None, obj=self, - id='contenttypes.E001', + id='fields.E001', ) ] else: @@ -82,7 +82,7 @@ class GenericForeignKey(six.with_metaclass(RenameGenericForeignKeyMethods)): "The GenericForeignKey object ID references the non-existent field '%s'." % self.fk_field, hint=None, obj=self, - id='contenttypes.E002', + id='contenttypes.E001', ) ] else: @@ -102,7 +102,7 @@ class GenericForeignKey(six.with_metaclass(RenameGenericForeignKeyMethods)): ), hint=None, obj=self, - id='contenttypes.E003', + id='contenttypes.E002', ) ] else: @@ -114,7 +114,7 @@ class GenericForeignKey(six.with_metaclass(RenameGenericForeignKeyMethods)): ), hint="GenericForeignKeys must use a ForeignKey to 'contenttypes.ContentType' as the 'content_type' field.", obj=self, - id='contenttypes.E004', + id='contenttypes.E003', ) ] elif field.rel.to != ContentType: @@ -125,7 +125,7 @@ class GenericForeignKey(six.with_metaclass(RenameGenericForeignKeyMethods)): ), hint="GenericForeignKeys must use a ForeignKey to 'contenttypes.ContentType' as the 'content_type' field.", obj=self, - id='contenttypes.E005', + id='contenttypes.E004', ) ] else: @@ -282,7 +282,7 @@ class GenericRelation(ForeignObject): return [] else: return [ - checks.Warning( + checks.Error( ("The GenericRelation defines a relation with the model " "'%s.%s', but that model does not have a GenericForeignKey.") % ( target._meta.app_label, target._meta.object_name diff --git a/django/db/models/base.py b/django/db/models/base.py index 6270e35b37..81e8c2216e 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1078,26 +1078,22 @@ class Model(six.with_metaclass(ModelBase)): except ValueError: errors.append( checks.Error( - '"%s" is not of the form "app_label.app_name".' % cls._meta.swappable, + "'%s' is not of the form 'app_label.app_name'." % cls._meta.swappable, hint=None, - obj=cls, - id='E002', + obj=None, + id='models.E001', ) ) except LookupError: app_label, model_name = cls._meta.swapped.split('.') errors.append( checks.Error( - ('The model has been swapped out for %s.%s ' - 'which has not been installed or is abstract.') % ( - app_label, model_name + ("'%s' references '%s.%s', which has not been installed, or is abstract.") % ( + cls._meta.swappable, app_label, model_name ), - hint=('Ensure that you did not misspell the model ' - 'name and the app name as well as the model ' - 'is not abstract. Does your INSTALLED_APPS ' - 'setting contain the "%s" app?') % app_label, - obj=cls, - id='E003', + hint=None, + obj=None, + id='models.E002', ) ) return errors @@ -1144,13 +1140,14 @@ class Model(six.with_metaclass(ModelBase)): if signature in seen_intermediary_signatures: errors.append( checks.Error( - ('The model has two many-to-many relations through ' - 'the intermediary %s model, which is not permitted.') % ( + ("The model has two many-to-many relations through " + "the intermediate model '%s.%s'.") % ( + f.rel.through._meta.app_label, f.rel.through._meta.object_name ), hint=None, obj=cls, - id='E004', + id='models.E003', ) ) else: @@ -1167,13 +1164,11 @@ class Model(six.with_metaclass(ModelBase)): if fields and not fields[0].primary_key and cls._meta.pk.name == 'id': return [ checks.Error( - ('You cannot use "id" as a field name, because each model ' - 'automatically gets an "id" field if none ' - 'of the fields have primary_key=True.'), - hint=('Remove or rename "id" field ' - 'or add primary_key=True to a field.'), + ("'id' can only be used as a field name if the field also " + "sets 'primary_key=True'."), + hint=None, obj=cls, - id='E005', + id='models.E004', ) ] else: @@ -1193,15 +1188,15 @@ class Model(six.with_metaclass(ModelBase)): if clash: errors.append( checks.Error( - ('The field "%s" from parent model ' - '%s clashes with the field "%s" ' - 'from parent model %s.') % ( + ("The field '%s' from parent model " + "'%s' clashes with the field '%s' " + "from parent model '%s'.") % ( clash.name, clash.model._meta, f.name, f.model._meta ), hint=None, obj=cls, - id='E053', + id='models.E005', ) ) used_fields[f.name] = f @@ -1220,13 +1215,13 @@ class Model(six.with_metaclass(ModelBase)): if clash and not id_conflict: errors.append( checks.Error( - ('The field clashes with the field "%s" ' - 'from model %s.') % ( - clash.name, clash.model._meta + ("The field '%s' clashes with the field '%s' " + "from model '%s'.") % ( + f.name, clash.name, clash.model._meta ), hint=None, obj=f, - id='E054', + id='models.E006', ) ) used_fields[f.name] = f @@ -1247,9 +1242,10 @@ class Model(six.with_metaclass(ModelBase)): if column_name and column_name in used_column_names: errors.append( checks.Error( - 'Field "%s" has column name "%s" that is already used.' % (f.name, column_name), - hint=None, + "Field '%s' has column name '%s' that is used by another field." % (f.name, column_name), + hint="Specify a 'db_column' for the field.", obj=cls, + id='models.E007' ) ) else: @@ -1263,10 +1259,10 @@ class Model(six.with_metaclass(ModelBase)): if not isinstance(cls._meta.index_together, (tuple, list)): return [ checks.Error( - '"index_together" must be a list or tuple.', + "'index_together' must be a list or tuple.", hint=None, obj=cls, - id='E006', + id='models.E008', ) ] @@ -1274,10 +1270,10 @@ class Model(six.with_metaclass(ModelBase)): for fields in cls._meta.index_together): return [ checks.Error( - 'All "index_together" elements must be lists or tuples.', + "All 'index_together' elements must be lists or tuples.", hint=None, obj=cls, - id='E007', + id='models.E009', ) ] @@ -1293,10 +1289,10 @@ class Model(six.with_metaclass(ModelBase)): if not isinstance(cls._meta.unique_together, (tuple, list)): return [ checks.Error( - '"unique_together" must be a list or tuple.', + "'unique_together' must be a list or tuple.", hint=None, obj=cls, - id='E008', + id='models.E010', ) ] @@ -1304,10 +1300,10 @@ class Model(six.with_metaclass(ModelBase)): for fields in cls._meta.unique_together): return [ checks.Error( - 'All "unique_together" elements must be lists or tuples.', + "All 'unique_together' elements must be lists or tuples.", hint=None, obj=cls, - id='E009', + id='models.E011', ) ] @@ -1329,23 +1325,23 @@ class Model(six.with_metaclass(ModelBase)): except models.FieldDoesNotExist: errors.append( checks.Error( - '"%s" points to a missing field named "%s".' % (option, field_name), - hint='Ensure that you did not misspell the field name.', + "'%s' refers to the non-existent field '%s'." % (option, field_name), + hint=None, obj=cls, - id='E010', + id='models.E012', ) ) else: if isinstance(field.rel, models.ManyToManyRel): errors.append( checks.Error( - ('"%s" refers to a m2m "%s" field, but ' - 'ManyToManyFields are not supported in "%s".') % ( + ("'%s' refers to a ManyToManyField '%s', but " + "ManyToManyFields are not permitted in '%s'.") % ( option, field_name, option ), hint=None, obj=cls, - id='E011', + id='models.E013', ) ) return errors @@ -1363,11 +1359,11 @@ class Model(six.with_metaclass(ModelBase)): if not isinstance(cls._meta.ordering, (list, tuple)): return [ checks.Error( - ('"ordering" must be a tuple or list ' - '(even if you want to order by only one field).'), + ("'ordering' must be a tuple or list " + "(even if you want to order by only one field)."), hint=None, obj=cls, - id='E012', + id='models.E014', ) ] @@ -1398,10 +1394,10 @@ class Model(six.with_metaclass(ModelBase)): except FieldDoesNotExist: errors.append( checks.Error( - '"ordering" pointing to a missing "%s" field.' % field_name, - hint='Ensure that you did not misspell the field name.', + "'ordering' refers to the non-existent field '%s'." % field_name, + hint=None, obj=cls, - id='E013', + id='models.E015', ) ) return errors diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py index fdc2917b34..dc78985dac 100644 --- a/tests/contenttypes_tests/tests.py +++ b/tests/contenttypes_tests/tests.py @@ -109,7 +109,7 @@ class GenericForeignKeyTests(IsolatedModelsTestCase): "The GenericForeignKey content type references the non-existent field 'TaggedItem.content_type'.", hint=None, obj=TaggedItem.content_object, - id='contenttypes.E003', + id='contenttypes.E002', ) ] self.assertEqual(errors, expected) @@ -127,7 +127,7 @@ class GenericForeignKeyTests(IsolatedModelsTestCase): "'Model.content_type' is not a ForeignKey.", hint="GenericForeignKeys must use a ForeignKey to 'contenttypes.ContentType' as the 'content_type' field.", obj=Model.content_object, - id='contenttypes.E004', + id='contenttypes.E003', ) ] self.assertEqual(errors, expected) @@ -145,7 +145,7 @@ class GenericForeignKeyTests(IsolatedModelsTestCase): "'Model.content_type' is not a ForeignKey to 'contenttypes.ContentType'.", hint="GenericForeignKeys must use a ForeignKey to 'contenttypes.ContentType' as the 'content_type' field.", obj=Model.content_object, - id='contenttypes.E005', + id='contenttypes.E004', ) ] self.assertEqual(errors, expected) @@ -162,7 +162,7 @@ class GenericForeignKeyTests(IsolatedModelsTestCase): "The GenericForeignKey object ID references the non-existent field 'object_id'.", hint=None, obj=TaggedItem.content_object, - id='contenttypes.E002', + id='contenttypes.E001', ) ] self.assertEqual(errors, expected) @@ -180,7 +180,7 @@ class GenericForeignKeyTests(IsolatedModelsTestCase): 'Field names must not end with an underscore.', hint=None, obj=Model.content_object_, - id='contenttypes.E001', + id='fields.E001', ) ] self.assertEqual(errors, expected) @@ -265,7 +265,7 @@ class GenericRelationshipTests(IsolatedModelsTestCase): errors = Bookmark.tags.field.check() expected = [ - checks.Warning( + checks.Error( ("The GenericRelation defines a relation with the model " "'contenttypes_tests.TaggedItem', but that model does not have a " "GenericForeignKey."), diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index c4ac960773..296e63f9f3 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -18,10 +18,10 @@ class IndexTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - '"index_together" must be a list or tuple.', + "'index_together' must be a list or tuple.", hint=None, obj=Model, - id='E006', + id='models.E008', ), ] self.assertEqual(errors, expected) @@ -34,10 +34,10 @@ class IndexTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - '"index_together" must be a list or tuple.', + "'index_together' must be a list or tuple.", hint=None, obj=Model, - id='E006', + id='models.E008', ), ] self.assertEqual(errors, expected) @@ -50,10 +50,10 @@ class IndexTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - 'All "index_together" elements must be lists or tuples.', + "All 'index_together' elements must be lists or tuples.", hint=None, obj=Model, - id='E007', + id='models.E009', ), ] self.assertEqual(errors, expected) @@ -68,10 +68,10 @@ class IndexTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - '"index_together" points to a missing field named "missing_field".', - hint='Ensure that you did not misspell the field name.', + "'index_together' refers to the non-existent field 'missing_field'.", + hint=None, obj=Model, - id='E010', + id='models.E012', ), ] self.assertEqual(errors, expected) @@ -88,11 +88,11 @@ class IndexTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ('"index_together" refers to a m2m "m2m" field, but ' - 'ManyToManyFields are not supported in "index_together".'), + ("'index_together' refers to a ManyToManyField 'm2m', but " + "ManyToManyFields are not permitted in 'index_together'."), hint=None, obj=Model, - id='E011', + id='models.E013', ), ] self.assertEqual(errors, expected) @@ -109,10 +109,10 @@ class UniqueTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - '"unique_together" must be a list or tuple.', + "'unique_together' must be a list or tuple.", hint=None, obj=Model, - id='E008', + id='models.E010', ), ] self.assertEqual(errors, expected) @@ -128,10 +128,10 @@ class UniqueTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - 'All "unique_together" elements must be lists or tuples.', + "All 'unique_together' elements must be lists or tuples.", hint=None, obj=Model, - id='E009', + id='models.E011', ), ] self.assertEqual(errors, expected) @@ -144,10 +144,10 @@ class UniqueTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - '"unique_together" must be a list or tuple.', + "'unique_together' must be a list or tuple.", hint=None, obj=Model, - id='E008', + id='models.E010', ), ] self.assertEqual(errors, expected) @@ -174,10 +174,10 @@ class UniqueTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - '"unique_together" points to a missing field named "missing_field".', - hint='Ensure that you did not misspell the field name.', + "'unique_together' refers to the non-existent field 'missing_field'.", + hint=None, obj=Model, - id='E010', + id='models.E012', ), ] self.assertEqual(errors, expected) @@ -194,11 +194,11 @@ class UniqueTogetherTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ('"unique_together" refers to a m2m "m2m" field, but ' - 'ManyToManyFields are not supported in "unique_together".'), + ("'unique_together' refers to a ManyToManyField 'm2m', but " + "ManyToManyFields are not permitted in 'unique_together'."), hint=None, obj=Model, - id='E011', + id='models.E013', ), ] self.assertEqual(errors, expected) @@ -276,20 +276,20 @@ class ShadowingFieldsTests(IsolatedModelsTestCase): errors = Child.check() expected = [ Error( - ('The field "id" from parent model ' - 'invalid_models_tests.mother clashes with the field "id" ' - 'from parent model invalid_models_tests.father.'), + ("The field 'id' from parent model " + "'invalid_models_tests.mother' clashes with the field 'id' " + "from parent model 'invalid_models_tests.father'."), hint=None, obj=Child, - id='E053', + id='models.E005', ), Error( - ('The field "clash" from parent model ' - 'invalid_models_tests.mother clashes with the field "clash" ' - 'from parent model invalid_models_tests.father.'), + ("The field 'clash' from parent model " + "'invalid_models_tests.mother' clashes with the field 'clash' " + "from parent model 'invalid_models_tests.father'."), hint=None, obj=Child, - id='E053', + id='models.E005', ) ] self.assertEqual(errors, expected) @@ -309,11 +309,11 @@ class ShadowingFieldsTests(IsolatedModelsTestCase): errors = Child.check() expected = [ Error( - ('The field clashes with the field "f_id" ' - 'from model invalid_models_tests.parent.'), + ("The field 'f' clashes with the field 'f_id' " + "from model 'invalid_models_tests.parent'."), hint=None, obj=Child._meta.get_field('f'), - id='E054', + id='models.E006', ) ] self.assertEqual(errors, expected) @@ -329,11 +329,11 @@ class ShadowingFieldsTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ('The field clashes with the field "fk" from model ' - 'invalid_models_tests.model.'), + ("The field 'fk_id' clashes with the field 'fk' from model " + "'invalid_models_tests.model'."), hint=None, obj=Model._meta.get_field('fk_id'), - id='E054', + id='models.E006', ) ] self.assertEqual(errors, expected) @@ -350,12 +350,10 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ('You cannot use "id" as a field name, because each model ' - 'automatically gets an "id" field if none of the fields ' - 'have primary_key=True.'), - hint='Remove or rename "id" field or add primary_key=True to a field.', + "'id' can only be used as a field name if the field also sets 'primary_key=True'.", + hint=None, obj=Model, - id='E005', + id='models.E004', ), ] self.assertEqual(errors, expected) @@ -368,11 +366,11 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ('"ordering" must be a tuple or list ' - '(even if you want to order by only one field).'), + ("'ordering' must be a tuple or list " + "(even if you want to order by only one field)."), hint=None, obj=Model, - id='E012', + id='models.E014', ), ] self.assertEqual(errors, expected) @@ -385,10 +383,10 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - '"ordering" pointing to a missing "missing_field" field.', - hint='Ensure that you did not misspell the field name.', + "'ordering' refers to the non-existent field 'missing_field'.", + hint=None, obj=Model, - id='E013', + id='models.E015', ) ] self.assertEqual(errors, expected) @@ -402,10 +400,10 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - '"TEST_SWAPPED_MODEL_BAD_VALUE" is not of the form "app_label.app_name".', + "'TEST_SWAPPED_MODEL_BAD_VALUE' is not of the form 'app_label.app_name'.", hint=None, - obj=Model, - id='E002', + obj=None, + id='models.E001', ), ] self.assertEqual(errors, expected) @@ -419,13 +417,11 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Model.check() expected = [ Error( - ('The model has been swapped out for not_an_app.Target ' - 'which has not been installed or is abstract.'), - hint=('Ensure that you did not misspell the model name and ' - 'the app name as well as the model is not abstract. Does ' - 'your INSTALLED_APPS setting contain the "not_an_app" app?'), - obj=Model, - id='E003', + ("'TEST_SWAPPED_MODEL_BAD_MODEL' references 'not_an_app.Target', " + 'which has not been installed, or is abstract.'), + hint=None, + obj=None, + id='models.E002', ), ] self.assertEqual(errors, expected) @@ -447,11 +443,11 @@ class OtherModelTests(IsolatedModelsTestCase): errors = Group.check() expected = [ Error( - ('The model has two many-to-many relations through ' - 'the intermediary Membership model, which is not permitted.'), + ("The model has two many-to-many relations through " + "the intermediate model 'invalid_models_tests.Membership'."), hint=None, obj=Group, - id='E004', + id='models.E003', ) ] self.assertEqual(errors, expected)