2010-12-08 118 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

相关问题