title: Django Multiple Databases - relation does not exist; LINE 1: SELECT COUNT(*) AS "__count" FROM
body: <p>I am using two databases, one of Mysql other is PostgreSql.</p>
  
  <ul>
  <li><p>Mysql is defined for 'default', PostgreSql is defined for 'location_db'</p></li>
  <li><p>and I have 5 app, let say 'a, b, c, d, location' apps,</p></li>
  <li><p>All apps should run every things on 'default' database except location app,</p></li>
  <li><p>I Just do ' python manage.py runserver ' then every things works fine, and even site works fine, but when I am at admin page and then click ' location ' admin model it runs error <strong>* relation "location_locationmodel" does not exist; LINE 1: SELECT COUNT(*) AS "__count" FROM "location_locationmodel" *</strong> at the other hands, if I click 'abcd' admin models, it just works fine.</p></li>
  </ul>
  
  <p>1) this is router.py (I just get the routers code from doc.django site maybe the codes are not for me, because I just guessing my router is not configured properly ? maybe ?)</p>
  
  <pre><code>class LocationRouter(object):
  
  """
      A router to control all database operations on models in the
      auth application.
      """
      def db_for_read(self, model, **hints):
          """
          Attempts to read auth models go to location_db.
          """
          if model._meta.app_label == 'location':
              return 'location_db'
          return None
  
      def db_for_write(self, model, **hints):
          """
          Attempts to write auth models go to location_db.
          """
          if model._meta.app_label == 'location':
              return 'location_db'
          return None
  
      def allow_relation(self, obj1, obj2, **hints):
          """
          Allow relations if a model in the events app is involved.
          """
          if obj1._meta.app_label == 'location' or \
             obj2._meta.app_label == 'location':
             return True
          return None
  
      def allow_migrate(self, db, app_label, model_name=None, **hints):
          """
          Make sure the auth app only appears in the 'location_db'
          database.
          """
          if app_label == 'location':
              return db == 'location_db'
          return None
  </code></pre>
  
  <p>2) this is settings.py</p>
  
  <pre><code>DATABASE_ROUTERS = ['location.router.LocationRouter']
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.mysql',
          #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
          'OPTIONS': {
              'read_default_file': os.path.join(BASE_DIR, 'my.cnf'),
          },
      },
      'location_db': {
          'ENGINE': 'django.contrib.gis.db.backends.postgis',
          'NAME': 'geo',
          'USER': 'john',
          'PASSWORD': 'toor',
          'HOST': 'localhost',
          'PORT': '5432',
      },
  }
  </code></pre>
  
  <p><strong>* My Predictions *</strong></p>
  
  <p>1) If I make another project and only use PostgreSql then every things works fine, So all databases works fine</p>
  
  <p>2) here is when I do 'python manage.py makemigrations or migrate':</p>
  
  <pre><code>Operations to perform:
    Apply all migrations: admin, auth, a, contenttypes, location, b, c, d, registration, sessions, sites
  Running migrations:
    No migrations to apply.
  </code></pre>
  
  <p><strong>* outcomes of migrate I think should not comes with 'location' app or maybe come <em></strong> . This is just prediction I don't really know but when I click ' location ' admin model on the admin page it runs error but it does not run error when I use only one databases, <strong></em> I mean does it searches the table still inside mysql database? could be the router is not configured properly ? *</strong></p>