【问题标题】:“settings.DATABASES is improperly configured” error performing syncdb with django 1.9“settings.DATABASES 配置不正确”使用 django 1.9 执行 syncdb 时出错
【发布时间】:2017-05-08 16:24:11
【问题描述】:

我开始了 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/'

有什么想法吗?提前致谢!

【问题讨论】:

    标签: django mongodb mongoengine database


    【解决方案1】:

    您没有正确配置 settings.py 文件中的数据库。您需要 DATABASE 配置设置,而不是将其添加到 INSTALLED_APP 中。

    配置

    DATABASES = {
       'default' : {
          'ENGINE' : 'django_mongodb_engine',
          'NAME' : 'my_database'
       }
    }
    

    Django MongoDB Engine 还考虑了 HOST、PORT、USER、PASSWORD 和 OPTIONS 设置。

    【讨论】:

      【解决方案2】:

      最简单的设置文件是使用 SQLite 的单一数据库设置。这可以使用以下配置:

      数据库 = { '默认': { '引擎': 'django.db.backends.sqlite3', 'NAME': '我的数据库', } }

      https://docs.djangoproject.com/en/1.10/ref/settings/#databases

      【讨论】:

        猜你喜欢
        • 2012-04-30
        • 2015-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-25
        • 1970-01-01
        • 1970-01-01
        • 2020-12-10
        相关资源
        最近更新 更多