Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1503 -- Improved model validator to throw an error if a model …

…doesn't manually define a primary key and has a field named 'id', which conflicts with the auto-primary-key convention. Thanks,

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 22da62f2391b88b524e33f79956db998b9522fb5 1 parent 0b92bd1
Adrian Holovaty authored

Showing 1 changed file with 2 additions and 0 deletions. Show diff stats Hide diff stats

  1. 2  django/core/
2  django/core/
@@ -815,6 +815,8 @@ def get_validation_errors(outfile, app=None):
815 815
816 816
         # Do field-specific validation.
817 817
         for f in opts.fields:
+            if == 'id' and not f.primary_key and == 'id':
+                e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' %
818 820
             if isinstance(f, models.CharField) and f.maxlength in (None, 0):
819 821
                 e.add(opts, '"%s": CharFields require a "maxlength" attribute.' %
820 822
             if isinstance(f, models.FloatField):

0 notes on commit 22da62f

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