我想使用来自DataStax Python Driver for Cassandra DB 的 ORM(使用数据创建一些类并自动从中创建一个表,而无需编写太多 CQL = )
我已经通过 docker 在 localhost 上部署了一个 Cassandra 服务器,并尝试像他们的手册中所写的那样做:
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 is created okay...
sync_table(Person) # And here's the error appears!
但是,唉,sync_table(...)
给我一个错误:
cassandra.cqlengine.CQLEngineException: Connection name '<object object at 0x7fbd95322ab0>' doesn't exist in the registry.
我该如何解决?