如何修复“设置”对象没有属性“ CASSANDRA_FALLBACK_ORDER_BY_PYTHON”

时间:2019-04-17 10:57:06

标签: django

我正在django项目中设置cassandra引擎,我成功运行了服务器,但是当我在管理站点中单击myapp的模型时出现错误:

Settings' object has no attribute 'CASSANDRA_FALLBACK_ORDER_BY_PYTHON

我首先同步cassandra,然后迁移它,在我运行服务器之后,没有错误,但是在管理站点中,当我想将数据放入模型中时出现此错误

For database I use django_cassandra_engine 

DATABASES = {
    'default': {
        'ENGINE': 'django_cassandra_engine',
        'NAME': 'db',
        'TEST_NAME': 'Test Cluster',
        'HOST': '127.0.0.1 ',
        'POST': '9042',
        'OPTIONS': {
            'replication': {
                'strategy_class': 'SimpleStrategy',
                'replication_factor': 1
            },
            'connection': {
                'consistency': ConsistencyLevel.LOCAL_ONE,
                'retry_connect': True
                # + All connection options for cassandra.cluster.Cluster()
            },
            'session': {
                'default_timeout': 10,
                'default_fetch_size': 10000
                # + All options for cassandra.cluster.Session()
            }
        }
}

我有这样的模型:

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

class mymodel(DjangoCassandraModel):
    name = columns.Text(required=True)
    phone = columns.Integer(primary_key=True)

in my terminal i get 

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/django_cassandra_engine/models/__init__.py", line 745, in order_by
    *self._get_ordering_condition(col))
  File "/usr/local/lib/python3.7/dist-packages/cassandra/cqlengine/query.py", line 1133, in _get_ordering_condition
    raise QueryException("Can't resolve the column name: '{0}'".format(colname))
cassandra.cqlengine.query.QueryException: Can't resolve the column name: 'pk'


  File "/usr/local/lib/python3.7/dist-packages/django/conf/__init__.py", line 80, in __getattr__
    val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'CASSANDRA_FALLBACK_ORDER_BY_PYTHON'

我也将rest_framework用于api视图 如何解决这类问题

1 个答案:

答案 0 :(得分:0)

在您的设置中添加以下内容:

CASSANDRA_FALLBACK_ORDER_BY_PYTHON = True