2016-06-25 6 views
0

実行している:私は「のpython manage.pyテスト」を実行しようとするとhttps://docs.djangoproject.com/en/1.9/intro/tutorial05/とValueError「のpython manage.pyテスト」私はこのサイトからのDjango tuturialを通じてつもりだ

iは、以下のエラーメッセージが表示されます:

python3.5でPyCharmでDjangoを実行していますか?誰もが問題の原因とその解決方法を知っていますか?

私apps.pyは次のようになります。ここでは

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 

はエラーメッセージです:

from django.apps import AppConfig 

class PollsConfig(AppConfig): 
    name = 'polls' 

と私のモデルのようになり

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) 
+0

する必要がありますあなたの質問は、models.pyとapps.py – ravigadila

+0

@RasmusRavnFrostしてください[編集](http://stackoverflow.com/posts/38029534/edit)を更新してください外部のソースにリンクするのではなく、コードを含めることをお勧めします。 – knbk

+0

Ok、Ravi、あなたがリクエストしたファイルを追加しました。 https://bitbucket.org/RasmusRavnFrost/djangotestingforstackoverflow/src/52df96701310?at=master – RasmusRavnFrost

答えて

1

あなたには誤りがありますpolls/migrations/0001_initial.py line no 36to='polls.models.QUESTION'

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

それはto='polls.Question'

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

ありがとう: はまた、私は必要な場合は、このリンクで、その全体でプロジェクトを表示する必要がありますビットバケットに公共フォークを追加しました。作品は今の魅力のように:)どのようなアイデアは、エラーがそこに得たか?なぜなら私はpolls/migrations/0001_initial.pyファイル内で手動の変更を行ったことがないからです。 – RasmusRavnFrost

+0

@RasmusRavnFrostこのエラーがなぜ発生したのか疑問に思うあなたのコードでエラーを再現できません! – ravigadila

+0

さて、それはなぜそれが謎なのかと思います。もう少し作業をした後、私はmodels.pyでsomの変更を加えたが、それらを適切に移行しなかったので、エラーが発生したと考えています。マイグレーション中に "manage.py runserver polls"を実行したままにしておくと、問題が発生する可能性があります。しかし、それはすべて純粋な推測です。とにかくありがとう。 – RasmusRavnFrost

関連する問題