# in intake.models
class FormSubmission(models.Model):
organizations = models.ManyToManyField('user_accounts.Organization')
# in user_accounts.models
class Organization(models.Model):
# some attributes
We now added an explicit through model
# in intake.models
class Application(models.Model):
organization = models.ForeignKey('user_accounts.Organization')
form_submission = models.ForeignKey(
'intake.Organization', db_column='formsubmission_id')
class Meta:
db_table = 'intake_formsubmission_organizations'
auto_created = True
class FormSubmission(models.Model):
organizations = models.ManyToManyField(
'user_accounts.Organization',
through='intake.Application')
Everything up to this point is fine. Tests work. We can create models and access relational queries.
We did not make a new migration because the table already existed and no changes to the database were needed.
Then we added a ForeignKey that points to the through model
# in intake.models
class StatusUpdate(models.Model):
application = models.ForeignKey('intake.Application')
When we try to make migrations for this new StatusUpdate model, Django returns an error