title: When is it required to use `schema_editor.connection.alias` in a django `migrations.RunPython` method?
body: <p>When is it required to use <code>schema_editor.connection.alias</code> in a <code>migrations.RunPython</code> method and why?</p>
  
  <p>When using RunPython in a data migration, <a href="https://docs.djangoproject.com/en/2.2/ref/migration-operations/#runpython" rel="noreferrer">django advises</a> that you should use <code>schema_editor.connection.alias</code>:</p>
  
  <pre><code>from django.db import migrations
  
  def forwards_func(apps, schema_editor):
      # We get the model from the versioned app registry;
      # if we directly import it, it'll be the wrong version
      Country = apps.get_model("myapp", "Country")
      db_alias = schema_editor.connection.alias
      Country.objects.using(db_alias).bulk_create([
          Country(name="USA", code="us"),
          Country(name="France", code="fr"),
      ])
  
  class Migration(migrations.Migration):
  
      dependencies = []
  
      operations = [
          migrations.RunPython(forwards_func, reverse_func),
      ]
  </code></pre>
  
  <blockquote>
    <p><strong>Warning</strong></p>
    
    <p><strong>RunPython</strong> does not magically alter the connection of the models for you; any model methods you call will go to the default database unless you give them the current database alias (available from <code>schema_editor.connection.alias</code>, where <code>schema_editor</code> is the second argument to your function).*</p>
  </blockquote>
  
  <p>But the docs section that <a href="https://docs.djangoproject.com/en/2.2/topics/migrations/#data-migrations" rel="noreferrer">describes data migrations</a>, it doesn't mention the <code>alias</code> at all:</p>
  
  <pre><code>from django.db import migrations
  
  def combine_names(apps, schema_editor):
      # We can't import the Person model directly as it may be a newer
      # version than this migration expects. We use the historical version.
      Person = apps.get_model('yourappname', 'Person')
      for person in Person.objects.all():
          person.name = '%s %s' % (person.first_name, person.last_name)
          person.save()
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('yourappname', '0001_initial'),
      ]
  
      operations = [
          migrations.RunPython(combine_names),
      ]
  </code></pre>