我在 django 中使用 Djongo 来使用 mongodb。我试图迁移模型所有模型都被迁移但是当我需要arrayfield时。当我试图迁移它时。它的错误。我尝试了所有可以在互联网上找到的东西。我在 manage.py 字段中尝试了 Django.setup 我尝试了所有东西,请帮助我。
我的设置代码
Django settings for questions project.
Generated by 'django-admin startproject' using Django 2.2.12.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
# 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/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'w6(hj1%1d=kc%z^$@0z4&r(02&00jz#-t%ql2l7g+!(csjr'
# 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',
'multi_questions',
]
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 = 'questions.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 = 'questions.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'question',
}
}
# Password validation
# https://docs.djangoproject.com/en/2.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/2.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/2.2/howto/static-files/
STATIC_URL = '/static/'
我的 manage.py 文件的代码
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
import django
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'questions.settings')
django.setup()
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
我的 models.py 文件的代码
from djongo import models
class multi_choice(models.Model):
choice_id = models.CharField(max_length=100)
choice_text = models.CharField(max_length=100)
class Meta:
abstract = True
class Question(models.Model):
question_text = models.CharField(max_length=1000)
options = models.ArrayField(model_container=multi_choice,size=4,default=list)
language = models.CharField(max_length=100)
objects = models.DjongoManager()
进行迁移时显示的错误是
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 9, in main
django.setup()
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/goodwin/Desktop/web_projects/questions/multi_questions/models.py", line 8, in <module>
class Question(models.Model):
File "/home/goodwin/Desktop/web_projects/questions/multi_questions/models.py", line 10, in Question
options = models.ArrayField(model_container=multi_choice,size=4,default=list)
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/djongo/models/fields.py", line 225, in __init__
super().__init__(model_container, *args, **kwargs)
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/djongo/models/fields.py", line 87, in __init__
self._validate_container()
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/djongo/models/fields.py", line 91, in _validate_container
for field in self.model_container._meta.get_fields():
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/db/models/options.py", line 734, in get_fields
return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/db/models/options.py", line 794, in _get_fields
all_fields = self._relation_tree
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/db/models/options.py", line 707, in _relation_tree
return self._populate_directed_relation_graph()
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/db/models/options.py", line 678, in _populate_directed_relation_graph
all_models = self.apps.get_models(include_auto_created=True)
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/apps/registry.py", line 178, in get_models
self.check_models_ready()
File "/home/goodwin/Desktop/env/web_dev/lib/python3.7/site-packages/django/apps/registry.py", line 140, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
请帮帮我。提前致谢