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

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

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

  1. TypeError: Unknown option(s) for sync_cassandra command:
  2. app_label, fake, fake_initial, interactive, migration_name, run_syncdb.
  3. 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数据库。

  1. """
  2. Django settings for project project.
  3. Generated by 'django-admin startproject' using Django 2.1.4.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/2.1/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/2.1/ref/settings/
  8. """
  9. import os
  10. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  11. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  12. # Quick-start development settings - unsuitable for production
  13. # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = 'm8m_d3=qx)&fq1j2xlz&b$(!=82#w3kljq(68n9-@%x*1=e70m'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = True
  18. ALLOWED_HOSTS = []
  19. # Application definition
  20. INSTALLED_APPS = [
  21. 'django_cassandra_engine',
  22. 'django.contrib.admin',
  23. 'django.contrib.auth',
  24. 'django.contrib.contenttypes',
  25. 'django.contrib.sessions',
  26. 'django.contrib.messages',
  27. 'django.contrib.staticfiles',
  28. 'rest_framework',
  29. 'rest_framework.authtoken',
  30. 'src.user',
  31. ]
  32. MIDDLEWARE = [
  33. 'django.middleware.security.SecurityMiddleware',
  34. 'django.contrib.sessions.middleware.SessionMiddleware',
  35. 'django.middleware.common.CommonMiddleware',
  36. 'django.middleware.csrf.CsrfViewMiddleware',
  37. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  38. 'django.contrib.messages.middleware.MessageMiddleware',
  39. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  40. ]
  41. ROOT_URLCONF = 'project.urls'
  42. TEMPLATES = [
  43. {
  44. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  45. 'DIRS': [],
  46. 'APP_DIRS': True,
  47. 'OPTIONS': {
  48. 'context_processors': [
  49. 'django.template.context_processors.debug',
  50. 'django.template.context_processors.request',
  51. 'django.contrib.auth.context_processors.auth',
  52. 'django.contrib.messages.context_processors.messages',
  53. ],
  54. },
  55. },
  56. ]
  57. WSGI_APPLICATION = 'project.wsgi.application'
  58. # Database
  59. # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
  60. from cassandra import ConsistencyLevel
  61. DATABASES = {
  62. 'sqlite': {
  63. 'ENGINE': 'django.db.backends.sqlite3',
  64. 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  65. },
  66. 'default': {
  67. 'ENGINE': 'django_cassandra_engine',
  68. 'NAME': 'project_db',
  69. 'USER': 'user',
  70. 'PASSWORD': 'pass',
  71. 'TEST_NAME': 'test_db',
  72. 'HOST': '127.0.0.1',
  73. 'OPTIONS': {
  74. 'replication': {
  75. 'strategy_class': 'SimpleStrategy',
  76. 'replication_factor': 1
  77. },
  78. 'connection': {
  79. 'consistency': ConsistencyLevel.LOCAL_ONE,
  80. 'retry_connect': True
  81. # + All connection options for cassandra.cluster.Cluster()
  82. },
  83. 'session': {
  84. 'default_timeout': 10,
  85. 'default_fetch_size': 10000
  86. # + All options for cassandra.cluster.Session()
  87. }
  88. }
  89. }
  90. }
  91. # Password validation
  92. # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
  93. AUTH_PASSWORD_VALIDATORS = [
  94. {
  95. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  96. },
  97. {
  98. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  99. },
  100. {
  101. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  102. },
  103. {
  104. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  105. },
  106. ]
  107. # Internationalization
  108. # https://docs.djangoproject.com/en/2.1/topics/i18n/
  109. LANGUAGE_CODE = 'en-us'
  110. TIME_ZONE = 'UTC'
  111. USE_I18N = True
  112. USE_L10N = True
  113. USE_TZ = True
  114. # Static files (CSS, JavaScript, Images)
  115. # https://docs.djangoproject.com/en/2.1/howto/static-files/
  116. STATIC_URL = '/static/'
zz2j4svz

zz2j4svz1#

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

  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文档中的示例。

相关问题