2016-12-26 52 views
0

我遵循cassandra cqlengine教程。卡桑德拉cqlengine不反映模型架構變化 - 遷移

import uuid 
from cassandra.cqlengine import columns 
from cassandra.cqlengine import connection 
from datetime import datetime 
from cassandra.cqlengine.management import sync_table 
from cassandra.cqlengine.models import Model 

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", protocol_version=3) 
sync_table(ExampleModel) 

然而,當我在模型中改變字段,像如果我改變從文本類型爲整數類型字段描述,然後做一個sync_table,我沒有看到變化被反映在卡桑德拉的表的模式。這怎麼解決?

回答

0

有兩件事情錯在這裏:

  1. 在概念上,要嘗試的模式遷移。 python的apache Cassandra驅動程序尚未正式支持模式遷移。快速瀏覽this ticket會向你解釋我的意思。 (注:你可以新列的表中添加和sync_table將工作和你的新模式將反映但那不是嚴格意義上ALTER操作。)

  2. Cassandra的數據類型轉換在數據模型中必須遵循的CQL類型兼容性,其定義爲here。您嘗試從Integer轉換爲Float不兼容。

到目前爲止,用不兼容類型更新模式的唯一解決方案概述如下here。我對同樣的here開了一個單獨的討論。