Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango unique_together does not allow ForeignKey field across applications when syncdb is executed
    text
    copied!<p>I'm trying to create a unique constraint on my <code>TranslationRequest</code> model listed below. <code>TranslationRequest</code> has a foreign key relationship with a <code>MachineTranslator</code> model, which exists in another Django application. When I try to run syncdb, I get the error: <code>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.</code></p> <p>When I remove <code>translator</code> from the <code>unique_constraint</code> specification, syncdb runs correctly. Note: I'm using Sqlite3 as my back-end database.</p> <p>Here are the definitions of <code>TranslationRequest</code> and <code>SourceArticle</code>.</p> <pre><code>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')) </code></pre> <p>Here is the definition of <code>MachineTranslator</code>, in a different (but referenced Django application).</p> <pre><code>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() </code></pre> <p>Not all of the dependencies have been included in this code sample. Thanks for your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload