title: Custom django management command to populate countries with pycountry AttributeError
body: <p>I am trying to create a custom command to populate countries in admin from pycountry package. But I am getting confusing AttributeError that says I am not referencing it correctly. Can someone help me to identify my mistake?</p>
  
  <p>Project settings for management command is:</p>
  
  <pre><code>market/ 
      manage.py
      address/
          __init__.py
          models.py
          management/
              __init__.py
              commands/
                  __init__.py
                  market_populate_countries.py
          views.py
  </code></pre>
  
  <p>Management command code:</p>
  
  <pre><code>from __future__ import absolute_import
  import sys
  from optparse import make_option
  from default.core.loading import get_model
  from django.core.management.base import BaseCommand, CommandError
  
  class Command(BaseCommand):
      help = "Populates the list of countries with data from pycountry."
      option_list = BaseCommand.option_list + (
          make_option(
              '--no-shipping',
              action='store_false',
              dest='is_shipping',
              default=True,
              help="Don't mark countries for shipping"),
          make_option(
              '--initial-only',
              action='store_true',
              dest='is_initial_only',
              default=False,
              help="Exit quietly without doing anything if countries were already populated."),
      )
  
      def handle(self, *args, **options):
          try:
              import pycountry
          except ImportError:
              raise CommandError(
                  "You are missing the pycountry library. Install it with "
                  "'pip install pycountry'")
  
          if Country.objects.exists():
              if options.get('is_initial_only', False):
                  # exit quietly, as the initial load already seems to have happened.
                  self.stdout.write("Countries already populated; nothing to be done.")
                  sys.exit(0)
              else:
                  raise CommandError(
                      "You already have countries in your database. This command "
                      "currently does not support updating existing countries.")
  
          countries = [
              Country(
                  iso_3166_1_a2=country.alpha2,
                  iso_3166_1_a3=country.alpha3,
                  iso_3166_1_numeric=country.numeric,
                  printable_name=country.name,
                  name=getattr(country, 'official_name', ''),
                  is_shipping_country=options['is_shipping'])
              for country in pycountry.countries]
  
          Country.objects.bulk_create(countries)
          self.stdout.write("Successfully added %s countries." % len(countries))
  </code></pre>
  
  <p>Traceback:</p>
  
  <pre><code>C:\Users\Alikhan\amazonclone\market&gt;manage.py market_populate_countries
  Traceback (most recent call last):
    File "C:\Users\Alikhan\amazonclone\market\manage.py", line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
  354, in execute_from_command_line
      utility.execute()
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
  346, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 394,
   in run_from_argv
      self.execute(*args, **cmd_options)
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 445,
   in execute
      output = self.handle(*args, **options)
    File "C:\Users\Alikhan\amazonclone\market\address\management\commands\market_
  populate_countries.py", line 56, in handle
      for country in pycountry.countries]
    File "C:\Python27\lib\site-packages\pycountry\db.py", line 22, in __getattr__
      raise AttributeError
  AttributeError
  </code></pre>
  
  <p>This is irrelevant but following is the way I've customized source function for get_model to avoid any confusion.</p>
  
  <pre><code>from __future__ import absolute_import
  import sys
  import traceback
  from importlib import import_module
  
  from django.apps import apps
  from django.apps.config import MODELS_MODULE_NAME
  from django.conf import settings
  from django.core.exceptions import AppRegistryNotReady
  
  from .exceptions import (
      AppNotFoundError, ClassNotFoundError, ModuleNotFoundError)
  
  def get_model(app_label, model_name):
      try:
          return apps.get_model(app_label, model_name)
      except AppRegistryNotReady:
          if apps.apps_ready and not apps.models_ready:
              app_config = apps.get_app_config(app_label)
              import_module('%s.%s' % (app_config.name, MODELS_MODULE_NAME))
              return apps.get_registered_model(app_label, model_name)
          else:
              raise
  </code></pre>