title: In Django, does the intermediate model need to belong in the same file as the target model?
body: <p>When running a migration, I am currently getting this <em>lazy reference ValueError</em> whenever the model that I have a defined ManyToManyField is in a separate file from the model that I am targeting. However, when I place the two models in the same file, I am able to successfully run the mirgation.</p>
  
  <ol>
  <li>Why is this error happening?</li>
  <li>Is it possible to separate the models (community.py and community_member.py) into separate files?</li>
  </ol>
  
  <blockquote>
    <p>ValueError:  contains a
    lazy reference to fitness.communitymember, but app 'fitness' doesn't
    provide model 'communitymember'.</p>
  </blockquote>
  
  <p>My directory structure looks like this:</p>
  
  <pre><code>my_app
    |----fitness
         |----user.py
         |----community.py
         |----community_member.py
  </code></pre>
  
  <p><strong>community.py</strong></p>
  
  <pre><code>class Community(models.Model):
      id = models.AutoField(
          primary_key=True,
      )
      owner = models.ForeignKey(
          User,
      )
      members = models.ManyToManyField(
          User,
          through='CommunityMember',
          through_fields=('community', 'member')
      )
  
      class Meta:
          db_table = 'Communities'
  </code></pre>
  
  <p><strong>community_member.py</strong></p>
  
  <pre><code>class CommunityMember(models.Model):
      community = models.ForeignKey(
          Community,
          db_column='community_id'
      )
      member = models.ForeignKey(
          User,
          db_column='member_id',
      )
  
      class Meta:
          db_table = 'Community_Members'
  </code></pre>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>INSTALLED_APPS = [
      'my_app.fitness'
  ]           
  </code></pre>
  
  <p>If I place the contents of <strong>community_members.py</strong> inside of <strong>community.py</strong> the migration is successfully executes, but I am not sure why.</p>