Cassandra的create_keyspace_simple出错

时间:2016-02-28 17:20:19

标签: python cassandra cql cqlengine

我尝试使用cassandra通过kafka与Meetup流式api连接。 cqlengine似乎之前它是一个独立的项目,我使用的参考代码是在那个时候制作的。

之前,cqlengine.managementcreate_keyspace 现在,cassandra.cqlengine.managementcreate_keyspace_simple

我正在尝试创建密钥空间。

create_keyspace_simple('meetup', 'SimpleStrategy', 1)

然而,我得到了这个错误。 警告:

  

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/cqlengine/management.py:419:未设置UserWarning:CQLENG_ALLOW_SCHEMA_MANAGEMENT环境变量。该软件包的未来版本将需要此变量来启用管理功能         warnings.warn(MSG)

错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-45553511338c> in <module>()
      1 # create keyspace
      2 # keyspace name, keyspace replication strategy, replication factor
----> 3 create_keyspace_simple('meetup', 'SimpleStrategy', 1)

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/cqlengine/management.pyc in create_keyspace_simple(name, replication_factor, durable_writes)
     54     """
     55     _create_keyspace(name, durable_writes, 'SimpleStrategy',
---> 56                      {'replication_factor': replication_factor})
     57 
     58 

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/cqlengine/management.pyc in _create_keyspace(name, durable_writes, strategy_class, strategy_options)
     84         log.info("Creating keyspace %s ", name)
     85         ks_meta = metadata.KeyspaceMetadata(name, durable_writes, strategy_class, strategy_options)
---> 86         execute(ks_meta.as_cql_query())
     87     else:
     88         log.info("Not creating keyspace %s because it already exists", name)

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/metadata.so in cassandra.metadata.KeyspaceMetadata.as_cql_query (cassandra/metadata.c:17371)()

AttributeError: 'NoneType' object has no attribute 'export_for_schema'

1 个答案:

答案 0 :(得分:0)

根据documentation的外观,create_keyspace_simple接受以下参数列表:

create_keyspace_simple(name, replication_factor, durable_writes=True)
  
      
  • name(str) - 要创建的键空间的名称
  •   
  • replication_factor(int) - 密钥空间复制因子,与SimpleStrategy一起使用
  •   
  • durable_writes(bool) - 如果设置为False
  • ,则绕过写日志   

基于此,我认为如果删除'SimpleStrategy'参数,您的语句将有效。由于您使用的是create_keyspace_simple,因此暗示了SimpleStrategy,因此无论如何都不需要指定它。

create_keyspace_simple('meetup', 1)