Django迁移引发TypeError:sync_cassandra命令的未知选项 [英] Django migration raised TypeError: Unknown option(s) for sync_cassandra command
问题描述
我试图将Cassandra数据库用于Django rest应用程序.当我使用SQLite数据库时,迁移工作正常.但是,当我更改数据库以使用cassandra时,出现以下错误.
I trying to use Cassandra database for my Django rest application. When I am using SQLite database the migration working fine. However, when I am changing the database to use cassandra I am getting the following error.
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的键空间.
I am running cassandra service in another shell. Also I have created a Keyspace named project_db using cqlsh.
下面给出了setting.py文件.即使我将数据库更改为仅Cassandra,也就是删除SQLite数据库,我也遇到相同的错误.
The setting.py file is given below. I am getting the same error even I am changing my database to cassandra only i.e. removing the SQLite database.
"""
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/'
推荐答案
I believe that this is the result of a change in Django as of version 2.0, where the call_command()
function was updated to validate options passed to it. If the option can't be validated (i.e., does not appear in the code of whatever module you're drawing on), then you get this TypeError.
在代码库中搜索使用接收到的TypeError消息中列出的所有unknown选项的call_command()
实例.根据他们的目的,您可以考虑以下两种选择:
Search your code base for instances of call_command()
that use any of the unknowns options that are listed in the TypeError message you received. Depending on their purpose, you could consider two options:
- 从
call_command()
中删除未知选项
- 在包含
call_command()
且带有未知选项的文件中添加适当的parser.add_argument()
函数. - 显示在Django文档中的示例,此处. >
- Remove the unknown option from the
call_command()
- Add an appropriate
parser.add_argument()
function in the file containing thecall_command()
with unknown options. Example from the Django documentation shown here.
这篇关于Django迁移引发TypeError:sync_cassandra命令的未知选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!