我在 python 中创建cassandra模型,下面是我的代码
from uuid import uuid4
from uuid import uuid1
from cassandra.cqlengine import columns, connection
from cassandra.cqlengine.models import Model
from cassandra.cqlengine.management import sync_table
class BaseModel(Model):
__abstract__ = True
deleted = columns.Boolean(required=True, default=False)
created_timestamp = columns.TimeUUID(primary_key=True,
clustering_order='DESC',
default=uuid1)
class OtherModel(BaseModel):
__table_name__ = 'other_table'
id = columns.UUID(primary_key=True, default=uuid4)
if __name__ == '__main__':
connection.setup(hosts=['localhost'],
default_keyspace='test')
sync_table(OtherModel)
这给出了错误
python /tmp/test.py
Traceback (most recent call last):
File "/tmp/test.py", line 9, in <module>
class BaseModel(Model):
File "/usr/lib/python2.7/site-packages/cassandra/cqlengine/models.py", line 905, in __new__
raise ModelException("clustering_order may be specified only for clustering primary keys")
cassandra.cqlengine.models.ModelException: clustering_order may be specified only for clustering primary keys
如果我发表评论,clusturing_order
那么它的工作正常。
class BaseModel(Model):
__abstract__ = True
deleted = columns.Boolean(required=True, default=False)
created_timestamp = columns.TimeUUID(primary_key=True,
# clustering_order='DESC',
default=uuid1)
有什么方法可以clusting_order
在abstract
类中定义吗?
我必须created_timestamp
在每个模型中创建,所以我不能将它移动到每个模型。