How do others deal with circular refences in their models? I am building an app with models based on the existing mediawiki schema.
In that schema, for the purpose of this question, there are 3 tables: page, revision, and text. page is the whole page represented over time. revision is a single revision of the page. text is the content of 1 or more revisions (possibly more due to reverts). page 1->M revision M->1 text (so far) however, for performance reasons, page also has a reference to the latest text record. page 1->M revision M->1 text \======1-1=======/^ So, when declaring the model, I had class MwPage(meta.Model): .. page_latest = meta.ForeignKey(MwText) class MwText(meta.Model): ... class MwRevision(meta.Model): ... page = meta.ForeignKey(MwPage, verbose_name="page of revision") text = meta.ForeignKey(MwText, verbose_name="FK to mw_text.old_id") Except that page_latest complained that MwText didn't exist yet. So I did a lame stub: class MwText: pass before MwPage. This seems to mostly work, but (for example) django-admin.py sql emits two create statements for MwText. Has anyone else had this problem, and if so, what was your approach?