Followed 'Writing custom django-admin commands' - 'Apps aren't loaded yet.'!

63 views
Skip to first unread message

paul_d...@hotmail.com

unread,
Jul 11, 2019, 4:15:39 PM7/11/19
to Django users
I've got a basic Django site up and running and am now trying to write a custom command by following the "Writing custom django-admin commands" documentation.  However having followed it carefully I get this exception:

(myfrontier) C:\Users\PDS\git\myfrontier>set DJANGO_SETTINGS_MODULE=myfrontier.settings

(myfrontier) C:\Users\PDS\git\myfrontier>django-admin podcasts
Traceback (most recent call last):
  File "C:\virtualenv\myfrontier\Scripts\django-admin-script.py", line 11, in <module>
    load_entry_point('Django', 'console_scripts', 'django-admin')()
  File "C:\virtualenv\myfrontier\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\virtualenv\myfrontier\lib\site-packages\django\core\management\__init__.py", line 357, in execute
    django.setup()
  File "C:\virtualenv\myfrontier\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\virtualenv\myfrontier\lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "C:\virtualenv\myfrontier\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "C:\virtualenv\myfrontier\lib\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 "c:\users\pds\git\myfrontier\portal\management\podcasts.py", line 2, in <module>
    from portal.models import ShowEpisode
  File "c:\users\pds\git\myfrontier\portal\models.py", line 4, in <module>
    class Dir(models.Model):
  File "C:\virtualenv\myfrontier\lib\site-packages\django\db\models\base.py", line 103, in __new__
    app_config = apps.get_containing_app_config(module)
  File "C:\virtualenv\myfrontier\lib\site-packages\django\apps\registry.py", line 252, in get_containing_app_config
    self.check_apps_ready()
  File "C:\virtualenv\myfrontier\lib\site-packages\django\apps\registry.py", line 135, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

The first two lines of my custom command are just like the example in the doc...
from django.core.management.base import BaseCommand, CommandError
from portal.models import ShowEpisode

So what am I doing wrong?  Is the documentation just wrong?  A quick Google throws up lots of suggestions and a number of people hitting this so can someone from Django dev. give some proper chapter and verse on how to solve this please?

thanks,
Paul DS

Joe Reitman

unread,
Jul 13, 2019, 10:16:30 AM7/13/19
to Django users
Try following this tutorial:

It looks like you don't have apps registered in INSTALLED APPS. Also, I always use the 'python manage.py <custom command>' not the 'django-admin <custom command>'
Reply all
Reply to author
Forward
0 new messages