title: Django migrate multiple databases
body: <p>Environment: Django 2, Python 3.6, PostgreSQL (optional)</p>
  
  <p>I am writing an application with multiple models, some of them might be stored in different databases.</p>
  
  <p>Example:</p>
  
  <p>models.py  (might be in different apps)</p>
  
  <pre><code># this used to allow field 'database' to be processed in 'Meta'
  models.options.DEFAULT_NAMES = models.options.DEFAULT_NAMES + ('database', )
  
  class MyModel01(models.Model):
      ...
      # this goes to default database
  
  
  class MyModel02(models.Model):
      ...
  
      class Meta:
          database = 'mydb02'
  
  
  class MyModel03(models.Model):
      ...
  
      class Meta:
          database = 'mydb03'
  </code></pre>
  
  <p>routers.py:</p>
  
  <pre><code>class MyRouter(object):
      def db_for_read(self, model, **hints):
          return getattr(model._meta, 'database', None)
  
      def db_for_write(self, model, **hints):
          return getattr(model._meta, 'database', None)
  
      def allow_migrate(self, db, app_label, model_name=None, **hints):
          model = hints.get('model')
          if not model:
              return None
          if db != 'default':
              modelname = model_name or model._meta.model_name
              usedb = getattr(model._meta, 'database', None)
              if not usedb:
                  return False
  
              if modelname and usedb:
                  return usedb == db
              return False
          else:
              usedb = getattr(model._meta, 'database', 'default')
              return usedb == db
          return None
  </code></pre>
  
  <p>settings:</p>
  
  <pre><code>DATABASES: {
      'default': {
          # some db settings
      },
      'mydb02': {
          # db settings
      },
      'mydb03': {
          # the SAME db settings as for mydb02
      }
  }
  </code></pre>
  
  <p>The issue is that in settings there might be the same database set for all database aliases.</p>
  
  <p>When I run migrate the migration get applied to just one of the databases, but not always to required one. For example it gets applied to 'default', but not 'mydb03'.</p>
  
  <p>I suppose the mistake is in my router, but cannot find out correct implementation.</p>