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

Completed

Hello,

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

https://www.jetbrains.com/help/pycharm/step-4-creating-and-running-your-first-django-project.html

 

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:

https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey

 

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

https://www.jetbrains.com/help/pycharm/step-4-creating-and-running-your-first-django-project.html#creating_models

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.

Cheers,

Nick

0

Please sign in to leave a comment.