开发者

Django unique_together does not allow ForeignKey field across applications when syncdb is executed

I'm trying to create a unique constraint on my TranslationRequest model listed below. TranslationRequest has a foreign key relationship with a MachineTranslator model, which exists in another Django application. When I try to run syncdb, I get the error: Error: One or more models did not validate: wt_articles.translationrequest: "unique_together" refers to translator, a field that doesn't exist. Check your syntax.

When I remove translator from the unique_constraint specification, syncdb runs correctly. Note: I'm using Sqlite3 as my back-end database.

Here are the definitions of TranslationRequest and SourceArticle.

from wt_translation.models import MachineTranslator

class TranslationRequest(models.Model):
    article = models.ForeignKey(SourceArticle)
    target_language = models.ForeignKey(Language, db_index=True)
    date = models.DateTimeField(_('Request Date'))
    translator = models.ForeignKey(MachineTranslator),
    status = models.CharField(_('Request Status'),
                              max_length=32,
                              choices=TRANSLATION_STATUSES)

    class Meta:
        unique_together = ("article", "target_language", "translator")

cla开发者_高级运维ss SourceArticle(models.Model):
    title = models.CharField(_('Title'), max_length=255)
    language = models.ForeignKey(Language, db_index=True)
    timestamp = models.DateTimeField(_('Import Date'), default=datetime.now())
    doc_id = models.CharField(_('Document ID'), max_length=512)
    source_text = models.TextField(_('Source Text'))
    sentences_processed = models.BooleanField(_('Sentences Processed'))

Here is the definition of MachineTranslator, in a different (but referenced Django application).

class MachineTranslator(models.Model):
    shortname = models.CharField(_('Name'), max_length=50)
    supported_languages = models.ManyToManyField(LanguagePair)
    description = models.TextField(_('Description'))
    type = models.CharField(_('Type'), max_length=32, choices=TRANSLATOR_TYPES, default='Serverland'),
    timestamp = models.DateTimeField(_('Refresh Date'), default=datetime.now())
    is_alive = models.BooleanField()

Not all of the dependencies have been included in this code sample. Thanks for your help!


i dont' know if it is a typo but i see s "," comma at the end of the line where you declare your translator = models.ForeignKey(MachineTranslator)

This is why maybe the attribute is ot seens

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜