Django ForeignKey field name “check” raises SystemCheckError

228 views
Skip to first unread message

Eric Palmitesta

unread,
Feb 20, 2019, 12:25:46 PM2/20/19
to Django users
The Django docs (https://docs.djangoproject.com/en/1.11/topics/db/models/#field-name-restrictions) state there are only two restrictions on model field names:

  1. A field name cannot be a Python reserved word
  2. A field name cannot contain more than one underscore in a row

However, given the following example, it doesn't look like I can use the field name `check` as a ForeignKey.

    class Check(models.Model):


        name
= models.CharField(max_length=100)


   
class MyModel(models.Model):


       
# this works fine
       
#check = models.BooleanField()
       
       
# this breaks
        check
= models.ForeignKey(Check, on_delete=models.PROTECT, related_name='+')

Here's the error:

    $ python manage.py check
   
SystemCheckError: System check identified some issues:


    ERRORS
:
    myapp
.MyModel: (models.E020) The 'MyModel.check()' class method is currently overridden by <django.db.models.fields.related_descriptors.ForwardManyToOneDescriptor object at 0x03A818D0>


Are the docs wrong, or am I doing something wrong?

This project is using Python 2 and Django 1.11

Here's the StackOverflow question: https://stackoverflow.com/questions/54681167/

Tim Graham

unread,
Feb 20, 2019, 2:58:13 PM2/20/19
to Django users
I believe the warning is incorrect. See https://code.djangoproject.com/ticket/23615 for the disucssion.
Reply all
Reply to author
Forward
0 new messages