Я пытаюсь подключить свое приложение django к mongoDB, для этого я использовал djon go. Когда я создаю простую модель без встроенных документов, миграции проходят идеально, но когда я пытаюсь создать документ встроенной модели в своей модели, при запуске python manage.py makemigrations
.
появляется сообщение об ошибке «модели еще не загружены» Сначала я хотел бы знать, почему возникает эта ошибка и почему она возникает, когда я использую встроенные модели.
Python Код:
➜ reports tree
.
├── db.sqlite3
├── manage.py
├── rep
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── __pycache__
│ │ ├── __init__.cpython-36.pyc
│ │ └── models.cpython-36.pyc
│ ├── tests.py
│ └── views.py
└── reports
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-36.pyc
│ ├── settings.cpython-36.pyc
│ ├── urls.cpython-36.pyc
│ └── wsgi.cpython-36.pyc
├── settings.py
├── urls.py
└── wsgi.py
5 directories, 19 files
from djongo import models
from django import forms
class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
class Meta:
abstract = True
class BlogForm(forms.ModelForm):
class Meta:
model = Blog
fields = ('name', 'tagline')
class Author(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
class Meta:
abstract = True
class AuthorForm(forms.ModelForm):
class Meta:
model = Author
fields = ('name', 'email')
class Entry(models.Model):
blog = models.EmbeddedField(
model_container=Blog,
model_form_class=BlogForm
)
name = models.CharField(max_length = 225)
headline = models.CharField(max_length=255)
authors = models.ArrayField(
model_container=Author,
model_form_class=AuthorForm
)
(django-djongo) ➜ reports python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/jagl/Documents/Learning/Programming/Django/reports/rep/models.py", line 31, in <module>
class Entry(models.Model):
File "/home/jagl/Documents/Learning/Programming/Django/reports/rep/models.py", line 34, in Entry
model_form_class=BlogForm
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/djongo/models/fields.py", line 225, in __init__
super().__init__(model_container, *args, **kwargs)
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/djongo/models/fields.py", line 87, in __init__
self._validate_container()
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/djongo/models/fields.py", line 91, in _validate_container
for field in self.model_container._meta.get_fields():
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/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/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/db/models/options.py", line 794, in _get_fields
all_fields = self._relation_tree
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/db/models/options.py", line 707, in _relation_tree
return self._populate_directed_relation_graph()
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/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/jagl/.virtualenvs/django-djongo/lib/python3.6/site-packages/django/apps/registry.py", line 178, in get_models
self.check_models_ready()
File "/home/jagl/.virtualenvs/django-djongo/lib/python3.6/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.
Я использую:
son==0.5.8
dataclasses==0.7
Django==2.2.12
djongo==1.3.2
pymongo==3.10.1
python-dateutil==2.8.1
pytz==2020.1
six==1.15.0
sqlparse==0.2.4
Единственные ответы, которые я нашел, - это те, которые объясняют, как использовать модели при использовании сценарий, но это не мой случай. Спасибо за помощь