6

django 単体テストの実行中にエラーが発生しました。これまで経験したことがなく、午後中ずっとグーグルで調べていました。

django manage.py テストを実行した後、ターミナルでこのエラーが発生します。

Error: Database test_unconvention couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: (1146, "Table 'test_unconvention.media_image' doesn't exist")

django-admin.py sqlflush を実行すると media_images テーブルが参照され、django manage.py syncdb を実行すると ok が生成されます。

これは、問題があるように見える画像モデルです。

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

class Image(models.Model):
  local_image = models.ImageField(upload_to="uploads/%Y/%m/%d/", height_field="height", width_field="width", max_length=255, null=True, blank=True)
  remote_image = models.CharField(editable=False, max_length=255, null=True, blank=True)
  thirdparty_page = models.CharField(editable=False, max_length=255, blank=True, null=True)
  size = models.CharField(editable=False, max_length=25, blank=True, null=True)
  content_type = models.ForeignKey(ContentType)
  object_id = models.PositiveIntegerField()
  content_object = generic.GenericForeignKey('content_type', 'object_id')
  height = models.PositiveIntegerField(editable=False, blank=True, null=True)
  width = models.PositiveIntegerField(editable=False, blank=True, null=True)
  created_at = models.DateTimeField(editable=False, auto_now_add=True)
  updated_at = models.DateTimeField(editable=False, auto_now=True)

  def __unicode__(self):
    if self.local_image:
      return self.local_image.name
    else:
      return self.remote_image

助けていただければ幸いです。さらに情報を提供する必要がある場合はお知らせください。

4

2 に答える 2

2

解決策:モデルが取得され、テストが実行できることを確認するために、親モジュール (例: ) だけでなくサブモジュール (例: common.media)を明示的に定義してください。INSTALLED_APPScommon

于 2011-07-01T10:58:46.737 に答える
0

を試してpython manage.py syncdbから戻る

于 2013-01-02T08:29:36.610 に答える