mongodb 为什么我会收到“未实现错误:在django中运行makemigration cmd时,数据库对象不执行真值测试或bool().”

e37o9pze  于 2022-11-03  发布在  Go
关注(0)|答案(8)|浏览(377)

我正在尝试使用Djongo连接Django和MongoDB。我已经更改了数据库参数,但是我得到了这个错误 * 未实现错误:运行makemigration命令时,数据库对象没有实现真值测试或bool().*。
请任何人可以解释为什么我得到这个错误,以及如何解决它?
我已经包括settings.py文件,错误日志和mongodb指南针设置图像。

设置.py

"""
Django settings for Chatify project.

Generated by 'django-admin startproject' using Django 3.2.9.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.

BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production

# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = 'django-insecure-1k4mo05el_0112guspx^004n-i&3h#u4gyev#27u)tkb8t82_%'

# 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',
    'api.apps.ApiConfig',
]

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 = 'Chatify.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 = 'Chatify.wsgi.application'

# Database

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

# DATABASES = {

# 'default': {

# 'ENGINE': 'django.db.backends.sqlite3',

# 'NAME': BASE_DIR / 'db.sqlite3',

# }

# }

DATABASES = {
       'default': {
           'ENGINE': 'djongo',
           'NAME': 'users',
       }
}

# Password validation

# https://docs.djangoproject.com/en/3.2/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.2/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.2/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type

# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

错误日志

File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 367, in run_from_argv
    connections.close_all()
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\utils.py", line 213, in close_all
    connection.close()
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\asyncio.py", line 33, in inner
    return func(*args,**kwargs)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\base\base.py", line 294, in close
    self._close()
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\djongo\base.py", line 208, in _close
    if self.connection:
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\pymongo\database.py", line 829, in __bool__
    raise NotImplementedError("Database objects do not implement truth "
NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None

蒙戈数据库指南针

qojgxg4l

qojgxg4l1#

问题出在新版本的pymongo(4.0 from 29.11.2021)上,Djongo 1.3.6支持这个版本。你需要安装pymongo 3.12.1。我两个小时前也遇到过同样的问题。

ajsxfq5m

ajsxfq5m2#

实际的问题是pymongo==4.0.1。当通过pip install mongoengine安装mongoengine时,它会安装pymongo==3.12.3。因此,没有必要再次安装mongoengine,只需通过pip install pymongo==3.12.3安装pymongo==3.12.3即可。

yi0zb3m4

yi0zb3m43#

把我的pymongo版本改回3.12.1,现在它能用了。

iyr7buue

iyr7buue4#

安装pymongo版本

pip install pymongo==3.12.3

或将python版本更改为3.7以下
由于版本变更发生错误

mwecs4sa

mwecs4sa5#

安装mongoengine对我很有效。命令:pip安装mongoengine

bd1hkmkf

bd1hkmkf6#

我在python==3.6.9上更改了我的python版本,现在它可以正常工作并成功迁移。

brc7rcf0

brc7rcf07#

我将pymongo版本更改为3.12.3,并解决了该问题

sbdsn5lh

sbdsn5lh8#

尝试安装django-mongoengine,它肯定会解决这个问题。

相关问题