I'm trying populate model from fixtures after starting Django.
I found out, that custom methods can be called in AppConfig
's ready()
method.
So, when I'm trying to do next:
class ApplicationConfig(AppConfig):
name = 'application'
def ready(self):
from django.core.management import call_command
call_command('loaddata', 'application/fixtures/some_info.json')
I got error message:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/app/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/app/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/venv/lib/python3.6/site-packages/django/apps/registry.py", line 83, in populate
raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn\'t reentrant
Is there any other ways to prepopulate model on start? Or, how to fix my problem?