如何解决带有pycharm的apache-cassandra数据库的Django
我正在尝试使用pycharm和apache-cassandra作为数据库,使用Django框架使用数据库模型创建消息应用程序。当我尝试跑步
python manage.py migrate
在终端中,我收到以下错误消息,
TypeError:sync_cassandra命令的未知选项:app_label,check_unapplied,fake,fake_initial,交互式,migration_name,plan,run_syncdb。有效选项包括:数据库,force_color,help,no_color,pythonpath,设置,skip_checks,stderr,stdout,回溯,详细程度,版本。
我的setting.py
"""
Django settings for DjangoProject project.
Generated by 'django-admin startproject' using Django 3.1.
For more information on this file,see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values,see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
from cassandra import ConsistencyLevel
# Build paths inside the project like this: BASE_DIR / 'subdir'.
from cassandra.cqlengine.connection import session
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 's6+mmj8j^9qe+jy&=@^2i!cao!fnxeicaa24c^@se8n@o88t&r'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','posts.apps.PostsConfig',]
INSTALLED_APPS = ['django_cassandra_engine'] + INSTALLED_APPS
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 = 'DjangoProject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [os.path.join(BASE_DIR,'templates')],'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 = 'DjangoProject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'sqlite': {
'ENGINE': 'django.db.backends.sqlite3','NAME': BASE_DIR / 'db.sqlite3','default': {
'ENGINE': 'django_cassandra_engine','NAME': 'my_keyspace','TEST_NAME': 'MasterTable','HOST': '127.0.0.1','OPTIONS': {
'replication': {
'strategy_class': 'SimpleStrategy','replication_factor': 1
},'connection': {
'consistency': ConsistencyLevel.SERIAL,'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/3.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/3.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/3.1/howto/static-files/
STATIC_URL = '/static/'
但是,当我使用sqlite3进行迁移时,我没有任何错误。
解决方法
可能您已经知道了。
答案是Cassandra不必迁移,而是sync_cassandra。
尝试: python manage.py sync_cassandra
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。