我试图创建一个表但是得到了这个错误 -
keyspace = cluster.metadata.keyspaces[ks_name]
KeyError: 'cqlengine'
型号:
import uuid
from cqlengine import columns
from cqlengine.models import Model
from datetime import datetime
from cqlengine.management import sync_table
class Tickets(Model):
ticket_id = columns.UUID(primary_key=True, default=uuid.uuid4)
created_dt = columns.DateTime(default=datetime.now())
division = columns.Text()
pg = columns.Text()
duration = columns.Text()
error_count = columns.Text()
outage_caused = columns.Text()
system_caused = columns.Text()
addt_notes = columns.Text()
ticket_num = columns.Text()
ticket_type = columns.Text()
row_create_ts = columns.DateTime(default=datetime.now())
row_end_ts = columns.DateTime(
default='9999-12-31 00:00:00.00000-00')
#connection.setup(['127.0.0.1'], "cqlengine", protocol_version=3)
# sync_table(Tickets)
from cqlengine import connection
connection.setup(["localhost"], "cqlengine")
sync_table(Tickets)
答案 0 :(得分:1)
错误是因为您尚未创建名为cqlengine
的密钥空间。您需要在使用之前创建密钥空间。在这种情况下,您需要使用cqlsh创建名为cqlengine
的密钥空间,然后再运行sync_table
。