title: Issue setting up a django database migration for an app with a model that has a relationship to another app in the same project
body: <p>I'm trying to setup two related apps in a django project, where one app's model references the other in a foreign key relationship. This is normally a simple thing, but I'm running into some collisions with app names (one of my apps is called 'account' and that's not unique in my installation) and my subsequent fix to that by adding in specific name/label definitions in a custom AppConfig may also be contributing to the problem.</p>
  
  <p>A little background on my environment:</p>
  
  <ul>
  <li>Django 1.8.3</li>
  <li>Python 2.7.6</li>
  <li>Postgres 9.4.0</li>
  <li>using this template for my project structure: <a href="https://github.com/pydanny/cookiecutter-django" rel="nofollow">https://github.com/pydanny/cookiecutter-django</a>.  Thanks pydanny!</li>
  </ul>
  
  <p>I setup a simple project using this template to demonstrate the problem: <a href="https://github.com/rishikumar/django_test_model" rel="nofollow">https://github.com/rishikumar/django_test_model</a></p>
  
  <p>Here are the relevant parts to the tree:</p>
  
  <pre><code>test/ (project app)
  /config ()
  /test (main django app)
      /account
          __init__.py
          apps.py
          models.py (Has a model called "Account")
      /schedule
          __init__.py
          apps.py 
          models.py (Has a model called "Schedule" which has a ForeignKey relationship to the Account table)
  </code></pre>
  
  <p>Here is the first model class, under the test/account app</p>
  
  <pre><code>class Account(models.Model):
      class Meta:
          db_table = 'test_account'
  </code></pre>
  
  <p>After putting this in place, I added this project to the INSTALLED_APPS as "test.account". I ran makemigrations next.</p>
  
  <pre><code>./manage.py makemigrations test.account
  </code></pre>
  
  <p>I was expecting this to uniquely identify the account package underneath the test project, but its only looking for the "account" part of the name. (I couldn't find any documentation explaining why this is the case)</p>
  
  <pre><code>django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: account
  </code></pre>
  
  <p>To work around this problem I setup a custom AppConfig for this.  in test/test/account/<strong>init</strong>.py I added the following: </p>
  
  <pre><code>default_app_config = 'test.account.apps.AppConfig'
  </code></pre>
  
  <p>And to test/test/account/apps.py I added: </p>
  
  <pre><code>class AppConfig(apps.AppConfig):
      name = 'test.account'
      label = 'test.account'
  </code></pre>
  
  <p>Now I can run make migrations as I originally intended and it works as expected. </p>
  
  <pre><code>./manage.py makemigrations test.account 
  </code></pre>
  
  <p>Incidentally, I gave the model a specific table name because it was specifying "test.account_account" by default and that causes some headaches in the postgres CLI - I have to quote the entire table name to reference it.</p>
  
  <p>I setup the second app the same way - added a default app config and setup the name and label of the app config to be "test.schedule"</p>
  
  <p>Here is the models.py in the schedule app:</p>
  
  <pre><code>from test.account.models import Account
  
  
  class Schedule(models.Model):
      class Meta:
          db_table = 'test_schedule'
  
      account = models.ForeignKey(Account)
  </code></pre>
  
  <p>Now I run makemigrations on this app:</p>
  
  <pre><code>./manage.py makemigrations test.schedule
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>ValueError: Lookup failed for model referenced by field test.schedule.Schedule.account: test.schedule.test.account.Account
  </code></pre>
  
  <p>Notice that the Account class that its trying to access says "test.schedule.test.account.Account" when it should referencing "test.account.Account"</p>
  
  <p>I'm not sure if my solution for the AppConfig entry was the right choice - perhaps there is a better way to uniquely identify an app within the django installation? </p>
  
  <p>I'm guessing that I'm making a bad decision about how to name things in my AppConfig, but I'm not sure how to reconcile the fact that I need to specify an AppConfig to avoid having duplicate application labels while still being able to avoid confusing the lookup for the foreign key reference that the migration tool is using. </p>