Django迁移引发TypeError:sync_cassandra命令的未知选项

时间:2019-01-06 07:24:58

标签: django cassandra django-rest-framework cqlengine

我试图将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/'

2 个答案:

答案 0 :(得分:1)

有关一致性级别,请参见:

datastax documentation / consistency

::使用不带任何选项的一致性来显示当前的一致性级别:

示例: 〜$一致性

当前一致性级别为ONE。

注意:在进入第一级之前,您可以将代码编辑为:

'consistency': ConsistencyLevel.SERIAL,

要检查其他参数的有效性!


答案 1 :(得分:0)

我相信这是a change in Django as of version 2.0的结果,其中call_command()函数已更新以验证传递给它的选项。如果无法验证该选项(即,该选项未出现在要绘制的任何模块的代码中),则将收到此TypeError。

在代码库中搜索call_command()的实例,这些实例使用您收到的TypeError消息中列出的任何未知选项。根据他们的目的,您可以考虑以下两种选择:

  1. call_command()删除未知选项
  2. 在包含parser.add_argument()且选项未知的文件中添加适当的call_command()函数。 Django文档中的示例显示为here