簡體   English   中英

CqlEngine - sync_table()KeyError:'cqlengine'

[英]CqlEngine - sync_table() KeyError: 'cqlengine'

我剛剛開始使用cqlengine在python中使用Cassandra。

我嘗試按照此鏈接嘗試運行此腳本:

from cqlengine import columns
from cqlengine import Model
from cqlengine import connection

from cqlengine.management import sync_table

import uuid


class ExampleModel(Model):
    example_id = columns.UUID(primary_key=True, default=uuid.uuid4)
    example_type = columns.Integer(index=True)
    created_at = columns.DateTime()
    description = columns.Text(required=False)


connection.setup(['127.0.0.1'], 'cqlengine')

sync_table(ExampleModel)

但它引發了這個錯誤:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zopper/Desktop/django-cassandra/local/lib/python2.7/site-packages/cqlengine/management.py", line 92, in sync_table
    keyspace = cluster.metadata.keyspaces[ks_name]
KeyError: 'cqlengine'

我的pip freeze是:

Django==1.7.3
argparse==1.2.1
blist==1.3.6
cassandra-driver==2.1.3
cqlengine==0.21.0
django-cassandra-engine==0.2.1
djangotoolbox==1.6.2
futures==2.2.0
six==1.9.0
wsgiref==0.1.2

請幫助我理解並解決這個問題。 謝謝。

這在我的結尾被忽略了 - 我現在正在修理它。 create_missing_keyspace很少“做正確的事情”,修復用錯誤參數創建的密鑰空間是非常困難和耗時的。 您現在必須使用所需的參數顯式創建鍵空間。

編輯create_missing_keyspace在cqlengine 0.21被忽略,而不是0.20。 嘗試<0.21的cqlengine或手動創建(見下文)。

創建一個這樣的鍵空間:

cqlengine.management.create_keyspace("cqlengine", replication_factor=1, strategy_class="SimpleStrategy")

可用的策略是SimpleStrategyNetworkTopologyStrategy

我找不到0.21的更新文檔,所以我檢查了源代碼 這是0.21中create_keyspace的聲明:

def create_keyspace(name, strategy_class, replication_factor, durable_writes=True, **replication_values):
    """
    creates a keyspace
    :param name: name of keyspace to create
    :param strategy_class: keyspace replication strategy class
    :param replication_factor: keyspace replication factor
    :param durable_writes: 1.2 only, write log is bypassed if set to False
    :param **replication_values: 1.2 only, additional values to ad to the replication data map
    """

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM