-1

I have a project which I have to develop with Django using Cassandra data base. I looked in there documentation but there is only information about mysql, sklite and postgre databases, nothing about Cassandra. I am looking for a sample way to connect Django to Cassandra:

I know i have to set the database configuration in the file setting.py:

    # Add "postgresql_psycopg2", "mysql", "sqlite3" or "oracle".    
    "ENGINE": "django.db.backends.cassandra",   
    # DB name or path to database file if using sqlite3.    
    "NAME": "test",           
    # Not used with sqlite3.    
    "USER": "",    
    enter code here# Not used with sqlite3.   
    "PASSWORD": "",    
    # Set to empty string for localhost. Not used with sqlite3.    
    "HOST": "127.0.0.1",    

but it throws an error:

Error was: No module named django_cassandra.base

Can anyone help me ?

Vinz
  • 5,997
  • 1
  • 31
  • 52
yaityaich
  • 1
  • 1
  • 3
  • possible duplicate of [How to use Cassandra in Django framework](http://stackoverflow.com/questions/2369793/how-to-use-cassandra-in-django-framework) – sundar nataraj May 07 '14 at 08:37

2 Answers2

2

You can use this pattern for your settings.py at Django Project folder:

    DATABASES = {
    'default': {
        'ENGINE': 'django_cassandra_engine', # Install this engine from https://pypi.org/project/django-cassandra-engine/
        'NAME': 'yourkeyspace', # the keyspace was created at cassandra 
        'USER': 'user',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',  # You can add your hosts here (use ,)
        'OPTIONS': {
            'replication': {
                'strategy_class': 'SimpleStrategy', # or any strategy you need
                'replication_factor': 1 # Depend on your decision
            },
            'connection': {
                'consistency': ConsistencyLevel.ONE,
                'lazy_connect': True,
                'retry_connect': True,
                'port': 9042, # default port
                #  You can add any connection options for cassandra.Cluster() here!
                          }
                     }
              }
        }
1

Django does not currently support nosql as backends. There is a nice django-like ORM called cqlengine, https://github.com/cqlengine/cqlengine, which is actively being developed and the datastax team says they are working with the cqlengine people. Although you can't use the database defs in settings.py, you can use django-like commands, for example, thingy.objects.all() to access your cassandra.

The native datastax python driver found on the datastax site, is more cqlsh oriented, may remind you of the oracle connector but is a bit faster.

The answer recommended in the link is very old.

Hope this helps.

Carilda
  • 161
  • 2
  • 12