r4fek / django-cassandra-engine

Django Cassandra Engine - the Cassandra backend for Django
BSD 2-Clause "Simplified" License
364 stars 85 forks source link

Multiple cassandra configurations #144

Open akap97 opened 3 years ago

akap97 commented 3 years ago

I have multiple cassandra configurations. my settings.py is as follows: DATABASES = { 'db1': { 'ENGINE': 'django_cassandra_engine', 'NAME': 'keyspace1', 'HOST': 'host1', 'PORT': port1, 'OPTIONS': { 'replication': { 'strategy_class': 'SimpleStrategy', 'replication_factor': 'factor1' } } } 'db2': { 'ENGINE': 'django_cassandra_engine', 'NAME': 'keyspace2', 'HOST': 'host2', 'PORT': port2, 'OPTIONS': { 'replication': { 'strategy_class': 'SimpleStrategy', 'replication_factor': 'factor2' } } } } ...and so on How to programmatically connect to different cassandra configurations when querying cassandra models. DB router is not working with cassandra.

r4fek commented 3 years ago

For example Model.objects.using('db2').filter(...)

akap97 commented 3 years ago

For example Model.objects.using('db2').filter(...)

It is giving me cassandra.cqlengine.CQLEngineException: Connection name '<object object at 0x7fd0fe35d0a0>' doesn't exist in the registry.

akap97 commented 3 years ago

For example Model.objects.using('db2').filter(...)

It is giving me: cassandra.cqlengine.CQLEngineException: Connection name '<object object at 0x7fd0fe35d0a0>' doesn't exist in the registry.

r4fek commented 3 years ago

Please take a look at following example from testproject: https://github.com/r4fek/django-cassandra-engine/blob/f6d74090d560c7e9d86877051bb693d342de10b7/testproject/multiapp/models.py https://github.com/r4fek/django-cassandra-engine/blob/f6d74090d560c7e9d86877051bb693d342de10b7/testproject/settings/multi_cassandra.py#L34

akap97 commented 3 years ago

Please take a look at following example from testproject: https://github.com/r4fek/django-cassandra-engine/blob/f6d74090d560c7e9d86877051bb693d342de10b7/testproject/multiapp/models.py

https://github.com/r4fek/django-cassandra-engine/blob/f6d74090d560c7e9d86877051bb693d342de10b7/testproject/settings/multi_cassandra.py#L34

I am creating models by inheriting DjangoCassandraModel not models.Model(as in example project). DjangoCassandraModel does not have __connection__ property. Also is it possible to specify the connection while hitting the APIs and not in the model itself?