我在 python 中有以下类,并使用 cqlengine 作为 cassandra DB 的对象映射器,
class Company(Model):
id = columns.Integer(index=True, primary_key=True)
company_name = columns.Text(required=False)
created_at = columns.DateTime(default=datetime.now)
class Social(Model):
id = columns.Integer(index=True, primary_key=True)
name = columns.Text(required=False)
class UserCompany(Model):
id = columns.Integer(index=True, primary_key=True)
user_id = columns.Integer(required=True)
company_id = columns.Integer(required=True)
array_of_tables=[UserCompany, Company, Social]
for table in array_of_tables:
sync_table(table)
问题:执行代码时,我无法在 cassandra 中创建两个以上的表。
错误信息:
File "test.py", line 109, in <module>
create_tables()
File "test.py", line 68, in create_tables
sync_table(table)
File "/usr/lib64/python2.6/site-packages/cassandra/cqlengine/management.py", line 259, in sync_table
execute(qs)
File "/usr/lib64/python2.6/site-packages/cassandra/cqlengine/connection.py", line 171, in execute
result = session.execute(query, params, timeout=timeout)
File "cassandra/cluster.py", line 1602, in cassandra.cluster.Session.execute (cassandra/cluster.c:27334)
File "cassandra/cluster.py", line 3347, in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:65206)
cassandra.InvalidRequest: code=2200 [Invalid query] message="Cannot create secondary index on partition key column id"
需要您帮助解决此问题。