I am starting to learn Python and Django, having never used them before. I'm following the tutorial at: https://docs.djangoproject.com/en/1.10/intro/tutorial05/ and have got as far as the 'Running Tests' section.
When I try to run the test using the command:
python manage.py test polls
the tutorial says that I should get an error that says:
AssertionError: True is not False
However, when I run this, having followed what the tutorial says, the error that I'm getting says:
django.db.utils.IntegrityError: (1217, 'Cannot delete or update a parent row: a foreign key constraint fails')
My models.py
file looks like this:
from __future__ import unicode_literals
import datetime
from django.db import models
from django.utils import timezone
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
Can anyone explain why I'm getting a different error to the one the tutorial tells me to expect? What am I doing wrong here?