2010-12-08 126 views
1

我試圖在下面列出的TranslationRequest型號上創建唯一約束。 TranslationRequest與另一個Django應用程序中存在的MachineTranslator模型有外鍵關係。當我嘗試運行syncdb時,出現以下錯誤: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.執行syncdb時,Django unique_together不允許跨應用程序使用ForeignKey字段

當我從unique_constraint規範中刪除translator時,syncdb運行正常。注意:我使用Sqlite3作爲我的後端數據庫。

以下是TranslationRequestSourceArticle的定義。

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") 

class 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')) 

這裏是MachineTranslator定義,在一個不同的(但引用Django應用程序)。

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() 

並非所有的依賴包含在此代碼示例中。謝謝你的幫助!

回答

0

我不」知道這是否是一個錯字,但我看到的‘’逗號在您申報您的翻譯= models.ForeignKey(MachineTranslator)

這就是爲什麼也許屬性是行的末尾ot seens

+0

謝謝,這是一個愚蠢的錯誤。顯然這個逗號只在嘗試通過unique_together訪問字段時給了我一個錯誤。否則,該字段可用於代碼中的其他地方。 – 2010-12-29 12:39:16

相關問題