title: Python Django: Minimal Django + Cassandra local application
body: <p>I am trying to put together a minimum Django application that uses Cassandra as the database. </p>
  
  <p>Here is what I tried:  </p>
  
  <ol>
  <li>Started a brand new Django project in PyCharm. Checked that <code>python manage.py runserver</code> works as expected.   </li>
  <li>Installed Cassandra using the instructions <a href="http://wiki.apache.org/cassandra/DebianPackaging" rel="nofollow">here</a>. I had to change the <code>rpc_port</code> and <code>storage_port</code> to numbers lower than 9000 to get this to work (probably something to do with my firewall).  Cassandra is running, and I am able to execute instructions using <code>cqlsh</code>.   </li>
  <li>Installed <a href="http://r4fek.github.io/django-cassandra-engine/" rel="nofollow"><code>cassandra-django-engine</code></a>.  </li>
  <li><p>Made the following changes to the <code>settings.py</code> file:  </p>
  
  <ul>
  <li><p>Added <code>django_cassandra_engine</code> to the front of the <code>INSTALLED_APPS</code> tuple:    </p>
  
  <pre><code>INSTALLED_APPS = (
  'django_cassandra_engine',
  'django.contrib.admin',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles',
  )
  </code></pre></li>
  <li><p>Replaced SQLite as the database to Cassandra, like so: </p>
  
  <pre><code>DATABASES = {
     'default': {
       'ENGINE': 'django_cassandra_engine',
       'NAME': 'db',
       'TEST_NAME': 'test_db',
       'HOST': 'localhost',
       'PORT': '8160',
       'OPTIONS': {
         'replication': {
         'strategy_class': 'SimpleStrategy',
         'replication_factor': 1
        }
      }
    }
  } 
  </code></pre>
  
  <p>Note that this is the part that I am least sure about. I could not figure out, based on the documentation what the parameters <code>NAME</code> and <code>TEST_NAME</code> are supposed to be. Note also that I have added a <code>'PORT'</code> key and that the port number defaults to <code>9160</code> but I have changed it to <code>8160</code> for the reasons mentioned above. Not sure I need to add this key.</p></li>
  </ul></li>
  </ol>
  
  <h1>Error information:</h1>
  
  <p>Here is a full traceback of the error from running a <code>python manage.py runserver</code> with the above project. Note that there are no apps defined in the project yet. </p>
  
  <pre><code>/usr/local/lib/python3.4/dist-packages/django/db/utils.py:238: RemovedInDjango19Warning: In Django 1.9 the TEST_NAME connection setting will be moved to a NAME entry in the TEST setting
    self.prepare_test_settings(alias)
  
  /usr/local/lib/python3.4/dist-packages/cassandra/util.py:486: UserWarning: The blist library is not available, so a pure python list-based set will be used in place of blist.sortedset for set collection values. You can find the blist library here: https://pypi.python.org/pypi/blist/
    "The blist library is not available, so a pure python list-based set will "
  
  Traceback (most recent call last):
    File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/models.py", line 7, in &lt;module&gt;
      from uwsgidecorators import postfork
    File "/usr/local/lib/python3.4/dist-packages/uwsgidecorators.py", line 10, in &lt;module&gt;
      import uwsgi
  ImportError: No module named 'uwsgi'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "manage.py", line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
      utility.execute()
    File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 312, in execute
      django.setup()
    File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 18, in setup
      apps.populate(settings.INSTALLED_APPS)
    File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 108, in populate
      app_config.import_models(all_models)
    File "/usr/local/lib/python3.4/dist-packages/django/apps/config.py", line 198, in import_models
      self.models_module = import_module(models_module_name)
    File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "&lt;frozen importlib._bootstrap&gt;", line 2254, in _gcd_import
    File "&lt;frozen importlib._bootstrap&gt;", line 2237, in _find_and_load
    File "&lt;frozen importlib._bootstrap&gt;", line 2226, in _find_and_load_unlocked
    File "&lt;frozen importlib._bootstrap&gt;", line 1200, in _load_unlocked
    File "&lt;frozen importlib._bootstrap&gt;", line 1129, in _exec
    File "&lt;frozen importlib._bootstrap&gt;", line 1471, in exec_module
    File "&lt;frozen importlib._bootstrap&gt;", line 321, in _call_with_frames_removed
    File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/models.py", line 12, in &lt;module&gt;
      cassandra_connection.connect()
    File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/base/__init__.py", line 94, in connect
      self.connection = CassandraConnection(**settings)
    File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/connection.py", line 52, in __init__
      self.setup()
    File "/usr/local/lib/python3.4/dist-packages/django_cassandra_engine/connection.py", line 59, in setup
      connection.setup(self.hosts, self.keyspace, **self.connection_options)
    File "/usr/local/lib/python3.4/dist-packages/cassandra/cqlengine/connection.py", line 129, in setup
      session = cluster.connect()
    File "/usr/local/lib/python3.4/dist-packages/cassandra/cluster.py", line 755, in connect
      self.control_connection.connect()
    File "/usr/local/lib/python3.4/dist-packages/cassandra/cluster.py", line 1868, in connect
      self._set_new_connection(self._reconnect_internal())
    File "/usr/local/lib/python3.4/dist-packages/cassandra/cluster.py", line 1903, in _reconnect_internal
      raise NoHostAvailable("Unable to connect to any servers", errors)
  cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'localhost': OperationTimedOut('errors=None, last_host=None',)})
  </code></pre>
  
  <p>From what I can understand,<br>
  1. There is a top level <code>ImportError</code>:</p>
  
  <pre><code>ImportError: No module named 'uwsgi'
  </code></pre>
  
  <p>2. And there is a nested error: </p>
  
  <pre><code>cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'localhost': OperationTimedOut('errors=None, last_host=None',)})
  </code></pre>
  
  <p>I am not sure which one of the two above is the more relevant error, and how to resolve the error in either case. Note that I have installed both the modules <code>uwsgi</code> and <code>uwsgidecorators</code>.</p>