question

Felix-Neko avatar image
Felix-Neko asked Erick Ramirez answered

Trying to use Model, getting CQLEngineException "Connection name ... does not exist"

Hi folks!

I want to use ORM from [DataStax Python Driver][1] for Cassandra DB (create some class with data and automatically create a table from it without writing too much CQL = )

I've deployed a Cassandra server on localhost via docker and tried to do just like it's written in manual

from cassandra.cluster import Cluster

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model
from cassandra.cqlengine.management import sync_table, create_keyspace_simple


class Person(Model):
    __keyspace__ = 'mega_keyspace'
    __table_name__ = 'person'
    id = columns.UUID(primary_key=True)
    first_name = columns.Text()
    last_name = columns.Text()


if __name__ == "__main__":
    cluster = Cluster()
    session = cluster.connect()
    # create_keyspace_simple("mega_keyspace", 2)
    session.execute("CREATE KEYSPACE IF NOT EXISTS mega_keyspace WITH REPLICATION = "
                "{ 'class' : 'SimpleStrategy', 'replication_factor' : 2 };")  # keyspace created okay
    sync_table(Person)  # And here's the exception = (

But alas, sync_table(...) gives me an error:

cassandra.cqlengine.CQLEngineException: Connection name '<object object at 0x7fbd95322ab0>' doesn't exist in the registry.

How can I fix it?

python driver
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

The error you posted indicates to me that the driver can't connect to the cluster.

The code sample you posted doesn't show how you've configured the connection so it's hard to know whether (a) you've just posted an incomplete example, or (b) you haven't told the driver the details of the cluster. That's where I would start investigating. Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.