简体   繁体   English

CqlEngine - sync_table()KeyError:'cqlengine'

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

I am just starting to work with Cassandra in python using cqlengine. 我刚刚开始使用cqlengine在python中使用Cassandra。

I tried following this link and tried ran this script: 我尝试按照此链接尝试运行此脚本:

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)

But it throws up this error: 但它引发了这个错误:

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'

My pip freeze is: 我的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

Please help me understand and solve this issue. 请帮助我理解并解决这个问题。 Thanks. 谢谢。

This was overlooked on my end - I'm fixing it now. 这在我的结尾被忽略了 - 我现在正在修理它。 create_missing_keyspace would rarely "do the right thing", and it's very difficult and time consuming to fix a keyspace created with the wrong parameters. create_missing_keyspace很少“做正确的事情”,修复用错误参数创建的密钥空间是非常困难和耗时的。 You must now explicitly create a keyspace with the parameters you want. 您现在必须使用所需的参数显式创建键空间。

Edit : The create_missing_keyspace is ignored in cqlengine 0.21, but not 0.20. 编辑create_missing_keyspace在cqlengine 0.21被忽略,而不是0.20。 Try a version < 0.21 of cqlengine or manual creation (see below). 尝试<0.21的cqlengine或手动创建(见下文)。

Create a keyspace like this : 创建一个这样的键空间:

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

The available strategies are SimpleStrategy and NetworkTopologyStrategy . 可用的策略是SimpleStrategyNetworkTopologyStrategy

I couldn't find updated docs for 0.21 so I checked the source . 我找不到0.21的更新文档,所以我检查了源代码 Here's the declaration of create_keyspace in 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