0

我有一个关注 ColumnFamily

class UniqueUserDealAction(models.Model):
    deal_id = columns.Text(primary_key=True)
    action = columns.Text(primary_key=True)
    imei1 = columns.Text(primary_key=True)
    imei2 = columns.Text(primary_key=True)
    event_time = columns.DateTime()
    created_at = columns.DateTime(default=datetime.now)

每当我尝试将数据插入 CF 时,

u = UniqueUserDealAction.create(deal_id='praful', action='India',
                                imei1='delhi', imei2='IT')

它返回我一个错误说 -

Traceback (most recent call last):
  File "/home/praful/Desktop/cube/c26-analytics/test.py", line 7, in <module>
    imei1='delhi', imei2='IT')
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cqlengine/models.py", line 583, in create
    return cls.objects.create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cqlengine/query.py", line 715, in create
    timestamp(self._timestamp).save()
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cqlengine/models.py", line 648, in save
    timeout=self._timeout).save()
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cqlengine/query.py", line 1028, in __init__
    self.column_family_name = self.model.column_family_name()
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cqlengine/models.py", line 483, in column_family_name
    return '{0}.{1}'.format(protect_name(cls._get_keyspace()), cf_name)
  File "cassandra/metadata.py", line 1231, in cassandra.metadata.protect_name (cassandra/metadata.c:27526)
  File "cassandra/metadata.py", line 1260, in cassandra.metadata.maybe_escape_name (cassandra/metadata.c:28214)
  File "cassandra/metadata.py", line 1264, in cassandra.metadata.escape_name (cassandra/metadata.c:28294)
AttributeError: 'NoneType' object has no attribute 'replace'
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/home/praful/Desktop/cube/c26-analytics/test.py"]
[dir: /home/praful/Desktop/cube/c26-analytics]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]

更新

这就是我创建密钥空间和 CF 的方式。

from cassandra.cqlengine import connection
from cassandra.cqlengine.management import sync_table, create_keyspace_simple

from models import UniqueUserDealAction

CQLENG_ALLOW_SCHEMA_MANAGEMENT = 'CQLENG_ALLOW_SCHEMA_MANAGEMENT'

CLUSTER_NODES = ['127.0.0.1']

connection.setup(CLUSTER_NODES, "mad")

create_keyspace_simple("mad", replication_factor=2)

sync_table(UniqueUserDealAction)
4

1 回答 1

1

看起来模型没有指定键空间。默认键空间来自连接设置。您还可以使用键空间模型属性指定键空间。

于 2016-01-15T14:31:08.130 回答