Ticket #15884: ticket_15884-patch_1.diff

File ticket_15884-patch_1.diff, 948 bytes (added by JustinTArthur, 7 years ago)

Patch to add validation error when a model field is both a primary key and nullable.

  • django/core/management/validation.py

    4040                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)
    4141            if f.name.endswith('_'):
    4242                e.add(opts, '"%s": Field names cannot end with underscores, because this would lead to ambiguous queryset filters.' % f.name)
     43            if f.primary_key and f.null:
     44                e.add(opts, '"%s: Primary key fields do not accept null values.' % f.name)
    4345            if isinstance(f, models.CharField):
    4446                try:
    4547                    max_length = int(f.max_length)
Back to Top