"Meet PyCharm" | "First Steps" | "Step 4" tutorial out of date (?) causing error - solution provided



I was going through “Step 4. Creating and Running Your First Django Project” at:



And the "Creating models" code seems to causes an error:

  File "C:\Users\nick\PycharmProjects\Step4\polls\models.py", line 25, in Choice

    question = models.ForeignKey(Question)

TypeError: __init__() missing 1 required positional argument: 'on_delete'


I looked into why, and apparently in Django 2.0 and after, the on_delete parameter is now required:



So, if you go back to the page, under the “Creating models” section:


The Choice class needs to be changed to include the on_delete parameter, perhaps something like what I have below:

class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.DO_NOTHING, )
    choice_test = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

    def __str__(self):
        return self.choice_test

I apologize if this isn’t the right place to post this, but hopefully this will help someone else new to Python/PyCharm and/or it’ll get noticed and fixed.



Please sign in to leave a comment.