Code

Ticket #1972: management.2.diff

File management.2.diff, 722 bytes (added by ubernostrum, 8 years ago)

Better patch; this puts it in model validation

Line 
1Index: management.py
2===================================================================
3--- management.py       (revision 3189)
4+++ management.py       (working copy)
5@@ -819,7 +819,10 @@
6     e = ModelErrorCollection(outfile)
7     for cls in models.get_models(app):
8         opts = cls._meta
9-
10+        # Check the model.
11+        if len(opts.fields) == 1 and opts.fields[0].get_internal_type() == 'AutoField':
12+            e.add(opts, "model '%s' in application '%s': A model must have at least one explicitly declared field." % (cls._meta.object_name, opts.app_label))
13+       
14         # Do field-specific validation.
15         for f in opts.fields:
16             if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':