Tutorial 5 (Testing) seems to have an error

150 views
Skip to first unread message

Eric Livingston

unread,
Feb 15, 2016, 11:16:51 AM2/15/16
to Django users

I have been walking through the Tutorial for Django, and upon reaching part 5 and introducing the first test case, I get this output (the directory I put the tutorial in is called 'demo')

 

RuntimeError: Model class demo.polls.models.Question doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

 

I tried adding a Meta section to the Question model, after doing some poking around in the docs.

 

class Question(models.Model):

    question_text = models.CharField(max_length=200)

    pub_date = models.DateTimeField('date published')

 

    class Meta:

        app_label='polls'

 

But then I get this:

 

RuntimeError: Conflicting 'question' models in application 'polls': <class 'polls.models.Question'> and <class 'demo.polls.models.Question'>.

 

What modifications would I have to make to the standard Tutorial code so the Models are correctly bound to the polls app? Do I have to add something else to the installed_apps besides 'polls.apps.PollsConfig'? That's the only thing the tutorial says to add.

 

Thanks,

Eric

Tim Graham

unread,
Feb 15, 2016, 2:02:55 PM2/15/16
to Django users
It looks like you have a Python path problem or that your project isn't structured correctly such that the model is being registered twice. Does that mean anything to you? I'm not sure if you are also new to Python or just to Django.

Nicolai Bjerre Pedersen

unread,
Dec 28, 2016, 7:17:48 AM12/28/16
to Django users
Hi Eric,

Did you find the bug? I have the same issue running python 2.7.12 and django 1.10.4

Nicolai Bjerre Pedersen

unread,
Dec 28, 2016, 7:17:48 AM12/28/16
to Django users
I figured it out. I had to either delete __init__.py in my root directory (where manage.py is located) or call python manage.py polls.tests instead of just python manage.py polls


Den mandag den 15. februar 2016 kl. 20.02.55 UTC+1 skrev Tim Graham:
Reply all
Reply to author
Forward
0 new messages