Si verifica un errore durante l'esecuzione dei test dell'unità django, non l'ho mai provato prima e ho cercato su Google tutto il pomeriggio.Test di Django non riuscito
sto ottenendo questo errore nel terminale dopo l'esecuzione di test di 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")
La tabella media_images viene fatto riferimento durante l'esecuzione sqlflush django-admin.py e genera ok quando corro django manage.py syncdb .
Questo è il modello di immagine che sembra essere problematico:
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
Apprezzo tutto l'aiuto, per favore fatemelo sapere se devo fornire maggiori informazioni!
Così quel modello Immagine vive nella tua app 'media', sì? È sicuramente nelle tue app installate in modo che venga sincronizzato dal testrunner? –
L'app multimediale si trova all'interno di un'app/progetto chiamato "comune", che avevo aggiunto alle mie app installate. Ho aggiunto "common.media" alla lista e le prove hanno funzionato, grazie :-) Se qualcun altro ha un problema simile, vale la pena notare che syncdb e sqlall hanno rilevato l'app multimediale senza problemi, e solo la gestione .py test fallito. –
Fresco. Sono contento che sia ordinato –