Changes between Version 1 and Version 2 of Ticket #31560, comment 3


Ignore:
Timestamp:
Jul 3, 2020, 4:43:26 PM (4 years ago)
Author:
HMaker

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31560, comment 3

    v1 v2  
    22> Thanks for this report, Can you provide a sample project? All my attempts raise an `ImportError` (even with circular imports in `apps.py`)
    33
    4 I had this problem and managed to debug it right now. It will happen when Django's app registry imports the app's module added in INSTALLED_APPS and that module imports, directly or indirectly, a model of the app being loaded . Reading the docs [https://docs.djangoproject.com/en/3.0/ref/applications/] there are no notes warning about it.
     4
     5Edit: Django docs [https://docs.djangoproject.com/en/3.0/ref/applications/#initialization-process] states that models must not be imported during apps population time.
     6So the OP should check whether models are being imported.
    57
    68**Steps to reproduce**
     
    10124. Add the app's dotted path to INSTALLED_APPS
    11135. Try to run with {{{ ./manage.py runserver }}}
    12 You will get the error {{{ django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. }}}. At a model's import time, the model metaclass will check whether its app is ready, but it is not, so the AppRegistryNotReady will be raised since the registry is being populated.
    13 
    14 Since it's caused by Django, I think Django should be able to detect it and output a meaning error message
Back to Top