In my app's "views.py" file I have the following import:
from .models import City
The import and the app work fine when launched on localhost.
In the same folder as "views.py" and "models.py" I have created another file "database_csv_imports.py" for making a one-time database import from .csv file.
If I would use the same line as above to import City
model into "database_csv_imports.py" file, I would get an error:
Traceback (most recent call last):
File "database_csv_imports.py", line 3, in <module>
from .models import City
SystemError: Parent module '' not loaded, cannot perform relative import
So I have changed relative import to absolute:
from models import City
This, however, throws another error:
Traceback (most recent call last):
File "database_csv_imports.py", line 3, in <module>
from models import City
File "/home/bart/python_projects/javascript/models.py", line 19, in <module>
class Listing(models.Model):
File "/home/bart/python_projects/testenv/lib/python3.5/site-packages/django/db/models/base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/bart/python_projects/testenv/lib/python3.5/site-packages/django/apps/registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "/home/bart/python_projects/testenv/lib/python3.5/site-packages/django/apps/registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I have looked at similar SO questions, but haven't found a solution:
I am running all scripts inside virtualenv, my app is installed in "settings.py", SECRET_KEY
is not empty, and both makemigrations
and migrate
are already applied. I also thought that the solution posted here: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. file init might me an overkill in this case.
Can someone help me fix the import error?