我开始使用Django 1.9的教程,我想将Mongoengine用于我的数据库..当我尝试迁移数据库“CMD: python manage.py migrate ”时我遇到了这个错误
[raise ImproperlyConfigured(“settings.DATABASES配置不正确”。 django.core.exceptions.ImproperlyConfigured:settings.DATABASES配置不正确。请提供ENGINE值。检查设置文档以获取更多详细信]
我的代码:settings.py
import os
from mongoengine import *
# 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/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3x80*9(7bdeg^lps-go9a8(@x_vmk#5vj66d9l0t3js(vknq(i'
# 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',
'mongoengine',
'TestApp'
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'testMongoDB.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 = 'testMongoDB.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
connect('myDB',username="NOUH",password="123456" )
SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy'
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/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/1.9/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/1.9/howto/static-files/
STATIC_URL = '/static/'
任何想法?提前谢谢!
答案 0 :(得分:1)
您没有正确配置settings.py文件中的DATABASES。不需要在INSTALLED_APP中添加它,而是需要DATABASE配置设置。
配置
DATABASES = {
'default' : {
'ENGINE' : 'django_mongodb_engine',
'NAME' : 'my_database'
}
}
Django MongoDB Engine还考虑了HOST,PORT,USER,PASSWORD和OPTIONS设置。
答案 1 :(得分:0)
最简单的设置文件是使用SQLite进行单数据库设置。可以使用以下方法配置:
DATABASES = { 'default':{ 'ENGINE':'django.db.backends.sqlite3', 'NAME':'mydatabase', }}
请参阅https://docs.djangoproject.com/en/1.10/ref/settings/#databases