0

I'm going through the Django tuturial from this site: https://docs.djangoproject.com/en/1.9/intro/tutorial05/

When I try to run "python manage.py test" i get the error message below:

Am running Django with PyCharm with python3.5. Does anyone know whats causing the problem and how to fix it?

my apps.py looks like this:

from django.apps import AppConfig

class PollsConfig(AppConfig):
    name = 'polls'

and my models look like this:

from django.db import models
from django.utils import timezone
import datetime

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

    def was_published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

    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

Here is the error message:

    Creating test database for alias 'default'...
Traceback (most recent call last):
  File "E:/Dropbox/WebPage/DjangoTestFolder/DjangoTest/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\commands\test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\commands\test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\commands\test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\test\runner.py", line 532, in run_tests
    old_config = self.setup_databases()
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\test\runner.py", line 482, in setup_databases
    self.parallel, **kwargs
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\test\runner.py", line 726, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\backends\base\creation.py", line 70, in create_test_db
    run_syncdb=True,
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\__init__.py", line 119, in call_command
    return command.execute(*args, **defaults)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\migrations\executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\migrations\executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\migrations\executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\migrations\migration.py", line 115, in apply
    operation.state_forwards(self.app_label, project_state)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\migrations\operations\fields.py", line 51, in state_forwards
    state.reload_model(app_label, self.model_name_lower)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\migrations\state.py", line 148, in reload_model
    self.apps.render_multiple(states_to_be_rendered)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\migrations\state.py", line 296, in render_multiple
    model.render(self)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\migrations\state.py", line 585, in render
    body,
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\models\base.py", line 158, in __new__
    new_class.add_to_class(obj_name, obj)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\models\base.py", line 307, in add_to_class
    value.contribute_to_class(cls, name)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\models\fields\related.py", line 706, in contribute_to_class
    super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\models\fields\related.py", line 306, in contribute_to_class
    lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\models\fields\related.py", line 86, in lazy_related_operation
    return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\models\fields\related.py", line 84, in <genexpr>
    model_keys = (make_model_tuple(m) for m in models)
  File "E:\Dropbox\Python\DjangoEnv\lib\site-packages\django\db\models\utils.py", line 13, in make_model_tuple
    app_label, model_name = model.split(".")
ValueError: too many values to unpack (expected 2)
3
  • please Update your question with models.py and apps.py Commented Jun 25, 2016 at 14:40
  • @RasmusRavnFrost Please edit the question to include the code rather than linking to an external source. Commented Jun 25, 2016 at 15:02
  • Ok, Ravi, I have added the files you requested. Also I added a public fork on bitbucket that should show the project in its entirety if needed, on this link: bitbucket.org/RasmusRavnFrost/djangotestingforstackoverflow/src/… Commented Jun 25, 2016 at 15:22

1 Answer 1

1

You have error in polls/migrations/0001_initial.py line no 36 to='polls.models.QUESTION'

field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.models.QUESTION'),

it should be to='polls.Question'

field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question'),
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Works like a charm now :) Any idea how that the error got there? Because I never made any manual changes in the polls/migrations/0001_initial.py file.
@RasmusRavnFrost i am unable to reproduce the error with your code wondering why this error occurred!
Well, I guess it's a mystery why then. After working with it some more, my best guess is that the error arose, because I made som changes in models.py, but didn't migrate them properly. I might have left the "manage.py runserver polls" running while doing migrations, which may be a problem. But that's all pure speculation. Thanks anyways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.