【问题标题】:CqlEngine - sync_table() KeyError: 'cqlengine'CqlEngine - sync_table() KeyError: 'cqlengine'
【发布时间】:2015-01-16 12:53:31
【问题描述】:

我刚刚开始使用 cqlengine 在 python 中使用 Cassandra。

我尝试关注此link 并尝试运行此脚本:

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

请帮助我理解并解决这个问题。 谢谢。

【问题讨论】:

    标签: python python-2.7 cassandra-2.0 cqlengine


    【解决方案1】:

    这被我忽略了 - 我现在正在修复它。 create_missing_keyspace 很少会“做正确的事”,修复使用错误参数创建的键空间非常困难且耗时。您现在必须使用所需的参数显式创建一个键空间。

    【讨论】:

    • 那么,我从源代码重新安装包?来自 GitHub?
    • 您需要使用 create_keyspace() 手动创建键空间。 sync_table 上的 create_missing_keyspace 参数消失了。我已经更新了自述文件:github.com/cqlengine/cqlengine/blob/master/README.md
    【解决方案2】:

    编辑create_missing_keyspace 在 cqlengine 0.21 中被忽略,但不是 0.20。尝试版本

    创建一个键空间like this:

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

    可用的策略是SimpleStrategyNetworkTopologyStrategy

    我找不到 0.21 的更新文档,所以我检查了 the source。这是 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
        """
    

    【讨论】:

    • 虽然文档显示该函数只接受一个参数name,但我收到此错误:Traceback(最近一次调用最后一次):文件“”,第 1 行,在 TypeError: create_keyspace() 至少需要 3 个参数(给定 1 个)
    • 我也试过sync_table(ExampleModel, create_missing_keyspace=True),但出现了同样的错误。并且文档说,create_missing_keyspace=True 是默认值。
    • 是的,我现在阅读了一些资料,文档令人困惑。特别是因为它已经过时了:)
    • 但是同一个版本!!!他们不会更改源并让文档保持不变,对吗?
    • 两天前的create_missing_keyspace 参数was removed。但是,它仍然存在于文档中。我发布了an issue on GitHub。它在 0.20 中仍然存在,因此您可能想尝试该版本。
    猜你喜欢
    • 2014-04-01
    • 1970-01-01
    • 2019-01-13
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多