# Tutorial problem

**URL:** <https://forum.djangoproject.com/t/tutorial-problem/656>\
**Category:** Using Django\
**Created:** [December 17, 2019, 3:45pm UTC](https://forum.djangoproject.com/t/tutorial-problem/656 "2019-12-17T15:45:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pnewbery](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pnewbery/32/457_2.png) [@pnewbery](https://forum.djangoproject.com/u/pnewbery)\
**Post date:** [December 17, 2019, 3:45pm UTC](https://forum.djangoproject.com/t/tutorial-problem/656/1 "2019-12-17T15:45:55Z")

</div>

I want to try out out Django and on my Linux Mint 19 PC have installed python 3.6.9 and Django 3.0 and am using the built-in SQLite3 for testing purposes although I do have MySQL installed on the PC.  
I am trying to do the tutorial but have twice come a cropper at the step in Part 2 of the tutorial where String Methods are added to polls/models/py. When in the shell, testing out if adding the methods has worked, in response to

> > Question.objects.all()  
> > I get  
> > \<QuerySet [\<Question: Question object (1)\>]\>  
> > instead of the expected:  
> > \<QuerySet [\<Question: What’s up?\>]\>  
> > All the preceding steps in the tutorial worked without a hitch. It is only when trying to add the def **str** (self): part (copied and pasted from the tutorial) that things don’t go according to plan.  
> > I am also unsure as to whether the “from django.db import models” line should be included again in the models.py file, since the very fist line is identical.  
> > Any help will be much appreciated.

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [December 17, 2019, 4:07pm UTC](https://forum.djangoproject.com/t/tutorial-problem/656/2 "2019-12-17T16:07:59Z")

</div>

Hi @pnewbery

That step in the tutorial is telling you to add the ` __str__ ` functions to the existing code. It sounds to me like you’ve instead understood it as copying the new code at the end of the `models.py` file?

You should have just this in your `models.py` after adding those methods:

```auto
from django.db import models

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    
    def __str__ (self):
        return self.question_text

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

```

---

<div class="post-metadata">

**Author:** ![pnewbery](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pnewbery/32/457_2.png) [@pnewbery](https://forum.djangoproject.com/u/pnewbery)\
**Post date:** [December 17, 2019, 4:29pm UTC](https://forum.djangoproject.com/t/tutorial-problem/656/3 "2019-12-17T16:29:36Z")

</div>

Thanks for that. Now it begins to make sense. However…  
Things get even more muddled. If I try to do:  
python3 manage.py makemigrations polls  
I get  
You are trying to add a non-nullable field ‘choice\_text’ to choice without a default; we can’t do that (the database needs something to populate existing rows).  
Please select a fix:

1. Provide a one-off default now (will be set on all existing rows with a null value for this column)
2. Quit, and let me add a default in models.py  
Select an option:

I don’t know what to do here.

If I run the shell, the response to:  
Question.objects.all() is now:  
Traceback (most recent call last):  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 86, in \_execute  
return self.cursor.execute(sql, params)  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py”, line 396, in execute  
return Database.Cursor.execute(self, query, params)  
sqlite3.OperationalError: no such column: polls\_question.question\_text

The above exception was the direct cause of the following exception:

Traceback (most recent call last):  
File “/usr/lib/python3.6/code.py”, line 91, in runcode  
exec(code, self.locals)  
File “”, line 1, in   
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/models/query.py”, line 252, in **repr**  
data = list(self[:REPR\_OUTPUT\_SIZE + 1])  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/models/query.py”, line 276, in **iter**  
self.\_fetch\_all()  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/models/query.py”, line 1261, in \_fetch\_all  
self.\_result\_cache = list(self.\_iterable\_class(self))  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/models/query.py”, line 57, in **iter**  
results = compiler.execute\_sql(chunked\_fetch=self.chunked\_fetch, chunk\_size=self.chunk\_size)  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 1137, in execute\_sql  
cursor.execute(sql, params)  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 100, in execute  
return super().execute(sql, params)  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 68, in execute  
return self.\_execute\_with\_wrappers(sql, params, many=False, executor=self.\_execute)  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 77, in \_execute\_with\_wrappers  
return executor(sql, params, many, context)  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 86, in \_execute  
return self.cursor.execute(sql, params)  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/utils.py”, line 90, in **exit**  
raise dj\_exc\_value.with\_traceback(traceback) from exc\_value  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/backends/utils.py”, line 86, in \_execute  
return self.cursor.execute(sql, params)  
File “/home/edwin/.local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py”, line 396, in execute  
return Database.Cursor.execute(self, query, params)  
django.db.utils.OperationalError: no such column: polls\_question.question\_text

Oops!!

---

<div class="post-metadata">

**Author:** ![pnewbery](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pnewbery/32/457_2.png) [@pnewbery](https://forum.djangoproject.com/u/pnewbery)\
**Post date:** [December 17, 2019, 6:33pm UTC](https://forum.djangoproject.com/t/tutorial-problem/656/4 "2019-12-17T18:33:08Z")

</div>

OK, it’s sorted! I started the project all over again and now that I understand the structure of models.py, it’s behaving as it should. My thanks to @adamchainz for putting me straight on this.
