mirror of
https://github.com/django/django.git
synced 2024-12-25 10:35:48 +00:00
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, mir@noris.de
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3100 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0b92bd11db
commit
22da62f239
@ -815,6 +815,8 @@ def get_validation_errors(outfile, app=None):
|
|||||||
|
|
||||||
# Do field-specific validation.
|
# Do field-specific validation.
|
||||||
for f in opts.fields:
|
for f in opts.fields:
|
||||||
|
if f.name == 'id' and not f.primary_key and opts.pk.name == '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.' % f.name)
|
||||||
if isinstance(f, models.CharField) and f.maxlength in (None, 0):
|
if isinstance(f, models.CharField) and f.maxlength in (None, 0):
|
||||||
e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name)
|
e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name)
|
||||||
if isinstance(f, models.FloatField):
|
if isinstance(f, models.FloatField):
|
||||||
|
Loading…
Reference in New Issue
Block a user