Django/Cassandra:无法创建超级用户

vh0rcniy  于 2022-09-27  发布在  Go
关注(0)|答案(2)|浏览(229)

我用Django和Cassandra运行Debian服务器。我无法通过以下命令创建管理员用户:

python manage.py createsuperuser

运行该命令会导致错误:

cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:260 no viable           alternative at input '.' (...auth_user.date_joined FROM auth_user WHERE [auth_user]....)">

同步工作正常-键空间和表是根据模型创建的。

问题

如何才能消除此错误并使命令正常工作?

版本信息

  • Debian GNU/Linux 8.6(杰西)
  • Python 2.7.9版
  • Django 1.10.5号
  • Cassandra3.0.9
    Django:设置.py

# Application definition

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django_cassandra_engine',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

# Database

# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django_cassandra_engine',
        'NAME': 'mydb',
        'TEST_NAME': 'test_db',
        'HOST': 'xx.xx.xx.xx',
        'OPTIONS': {
            'replication': {
                'strategy_class': 'SimpleStrategy',
                'replication_factor': 1
            }
        }
    }
}

完全回溯

Not checking migrations as it is not possible to access/create the django_migrations table.
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args,**cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/commands/createsuperuser.py", line 63, in execute
    return super(Command, self).execute(*args,**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args,**options)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/commands/createsuperuser.py", line 96, in handle
    default_username = get_default_username()
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/__init__.py", line 148, in get_default_username
    auth_app.User._default_manager.get(username=default_username)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args,**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 379, in get
    num = len(clone)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 238, in __len__
    self._fetch_all()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1087, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 54, in __iter__
    results = compiler.execute_sql()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django_cassandra_engine/utils.py", line 47, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django_cassandra_engine/connection.py", line 13, in execute
    return self.connection.execute(*args,**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django_cassandra_engine/connection.py", line 88, in execute
    return self.session.execute(qs, *args,**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1998, in execute
    return self.execute_async(query, parameters, trace, custom_payload, timeout, execution_profile, paging_state).result()
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 3781, in result
    raise self._final_exception
cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:260 no viable           alternative at input '.' (...auth_user.date_joined FROM auth_user WHERE [auth_user]....)">
vu8f3i0k

vu8f3i0k1#

Django Cassandra Engine v1.7.0(截至2022年9月16日)不支持存储在Cassandra-auth模块中的用户模型。
解决方法是用户模型的第二个数据库。

ghhaqwfi

ghhaqwfi2#

我们不能使用:

python manage.py createsuperuser using cassandra

它不适用于默认的django模型。
您需要使用外部库来进行相同的操作。
请阅读data stax上的文档或访问以下链接:https://pypi.python.org/pypi/django-cassandra-engine/

相关问题