[英]Cassandra cqlengine not reflecting model schema changes - migration
I followed the cassandra cqlengine tutorial. 我遵循了cassandra 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)
However when i change a field in the model, like if i change the field description from Text type to Integer type, and then do a sync_table, i dont see the change being reflected in the tables schema in cassandra. 但是,当我更改模型中的字段时,例如,如果我将字段描述从“文本”类型更改为“整数”类型,然后执行sync_table,则看不到该更改反映在cassandra的表模式中。 How can this be solved ?
如何解决呢?
There are two things wrong here: 这里有两件事是错误的:
Conceptually, you are attempting a schema migration. 从概念上讲,您正在尝试架构迁移。 The apache Cassandra driver for python does not really support schema migration officially yet.
python的Apache Cassandra驱动程序尚未真正真正支持架构迁移。 A quick look at this ticket will explain to you what I mean.
快速浏览这张票将向您解释我的意思。 (Note: you could add new column to your table and
sync_table
will work and your new schema will be reflected but that is not strictly speaking an ALTER
operation.) (注意:您可以向表中添加新列,并且
sync_table
将起作用并且新模式将得到反映,但严格来讲这并不是ALTER
操作。)
Cassandra data type conversions in a data model must follow the CQL type compatibility, which is defined here . 在数据模型中卡桑德拉数据类型转换必须遵循CQL类型的相容性,其被定义在这里 。 Your attempt to convert from
Integer
to Float
is not compatible. 您尝试从
Integer
转换为Float
不兼容。
The only solution so far to update schema with imcompatible types is outlined here . 此处概述了到目前为止使用不兼容类型更新架构的唯一解决方案。 I opened a separate discussion on the same here .
我在这里就同一问题展开了单独的讨论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.