django迁移引发typeerror:sync\u cassandra命令的未知选项

hmtdttj4  于 2021-06-14  发布在  Cassandra
关注(0)|答案(2)|浏览(357)

我正在尝试将cassandra数据库用于django rest应用程序。当我使用sqlite数据库时,迁移工作正常。但是,当我将数据库更改为使用cassandra时,我得到以下错误。

TypeError: Unknown option(s) for sync_cassandra command: 
 app_label, fake, fake_initial, interactive, migration_name, run_syncdb. 
 Valid options are database, help, no_color, pythonpath, settings, skip_checks, stderr, stdout, traceback, verbosity, version.

我在另一个shell中运行cassandra服务。我还使用cqlsh创建了一个名为project\ db的键空间。
setting.py文件如下所示。我得到同样的错误,即使我改变我的数据库Cassandra只,即删除sqlite数据库。

"""
    Django settings for project project.

    Generated by 'django-admin startproject' using Django 2.1.4.

    For more information on this file, see
    https://docs.djangoproject.com/en/2.1/topics/settings/

    For the full list of settings and their values, see
    https://docs.djangoproject.com/en/2.1/ref/settings/
    """

    import os

    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    # Quick-start development settings - unsuitable for production
    # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = 'm8m_d3=qx)&fq1j2xlz&b$(!=82#w3kljq(68n9-@%x*1=e70m'

    # SECURITY WARNING: don't run with debug turned on in production!
    DEBUG = True

    ALLOWED_HOSTS = []

    # Application definition

    INSTALLED_APPS = [
        'django_cassandra_engine',
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'rest_framework',
        'rest_framework.authtoken',
        'src.user',
    ]

    MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ]

    ROOT_URLCONF = 'project.urls'

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]

    WSGI_APPLICATION = 'project.wsgi.application'

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

    from cassandra import ConsistencyLevel

    DATABASES = {
        'sqlite': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        },
        'default': {
            'ENGINE': 'django_cassandra_engine',
            'NAME': 'project_db',
            'USER': 'user',
            'PASSWORD': 'pass',
            'TEST_NAME': 'test_db',
            'HOST': '127.0.0.1',
            '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()
                }
            }
        }
    }

    # Password validation
    # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
    ]

    # Internationalization
    # https://docs.djangoproject.com/en/2.1/topics/i18n/

    LANGUAGE_CODE = 'en-us'

    TIME_ZONE = 'UTC'

    USE_I18N = True

    USE_L10N = True

    USE_TZ = True

    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/2.1/howto/static-files/

    STATIC_URL = '/static/'
zz2j4svz

zz2j4svz1#

有关一致性级别,请参见以下内容:
税务文件/一致性
●使用不带选项的一致性,以显示当前的一致性级别:
示例:~$consistency
当前的一致性级别是1。
注意:在进入第一级之前,您可以编辑代码以:

'consistency': ConsistencyLevel.SERIAL,

检查其他参数的有效性!

vd8tlhqk

vd8tlhqk2#

我相信这是django在2.0版本中发生变化的结果,在2.0版本中 call_command() 已更新函数以验证传递给它的选项。如果该选项不能被验证(即,没有出现在您正在绘制的模块的代码中),那么您将得到这个typeerror。
在代码库中搜索 call_command() 使用您收到的typeerror消息中列出的任何未知选项。根据它们的用途,您可以考虑两种选择:
从中删除未知选项 call_command() 添加适当的 parser.add_argument() 包含 call_command() 有未知的选择。这里显示的django文档中的示例。

相关问题