title: how to handle exception in django multiple database
body: <p><a href="https://i.stack.imgur.com/Gbunn.png" rel="nofollow noreferrer">error screenshot</a></p>
  
  <pre><code>try:
      DATABASES = {
          'default': {
              'ENGINE': 'djongo',
              'NAME': 'jobstar',
          }
      }
  except:
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.sqlite3',
              'NAME': os.path.join(BASE_DIR, 'jobstar'),
          }
      }
  </code></pre>
  
  <p>How can i handle exception with database settings in django . my primary database is mongodb as shown. i want when mongo is not running or not installed in system it will use sqlite (secondary) database.</p>
  
  <p>i am trying to do this in above way it is throwing me errors.
  please have a look into my code</p>
  
  <pre><code>    t__
          self.loader = MigrationLoader(self.connection)
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
          self.build_graph()
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/django/db/migrations/loader.py", line 206, in build_graph
          self.applied_migrations = recorder.applied_migrations()
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
          if self.has_table():
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 44, in has_table
          return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 56, in table_names
          return get_names(cursor)
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 51, in get_names
          return sorted(ti.name for ti in self.get_table_list(cursor)
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/djongo/introspection.py", line 46, in get_table_list
          for c in cursor.db_conn.collection_names(False)
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/pymongo/database.py", line 715, in collection_names
          nameOnly=True, **kws)]
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/pymongo/database.py", line 674, in list_collections
          read_pref) as (sock_info, slave_okay):
        File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
          return next(self.gen)
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1099, in _socket_for_reads
          server = topology.select_server(read_preference)
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/pymongo/topology.py", line 224, in select_server
          address))
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/pymongo/topology.py", line 183, in select_servers
          selector, server_timeout, address)
        File "/home/soubhagya/Desktop/worke/rmaze-partner/rmaze-partner-env/lib/python3.6/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
          self._error_message(selector))
      pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
  </code></pre>