pythondjangocassandracqlengine

varchar column type in cassandra cqlengine


How to define a varchar field in django cassandra model.

from cassandra.cqlengine import columns
from django_cassandra_engine.models import DjangoCassandraModel

class ChatEvent(DjangoCassandraModel):
    interview_id = columns.UUID(partition_key=True)
    fire_time = columns.DateTime(primary_key=True, clustering_order="DESC")
    id = columns.UUID(primary_key=True)
    type = //to be varchar type
    data = columns.Text(required=True)
    created_by = columns.UUID(required=True)

This documentation lists all data types but it does not have a varchar type https://docs.datastax.com/en/drivers/python/2.5/api/cassandra/cqlengine/columns.html#:~:text=Columns%20in%20your%20models%20map,one%20non%2Dprimary%20key%20column.


Solution

  • varchar is the alias for text field (see the answer here), you need to use CqlEngine's Text data type.