title: Django: how to solve "Apps aren't loaded yet" error on model import?
body: <p>In my app's "views.py" file I have the following import:</p>
  
  <pre><code>from .models import City
  </code></pre>
  
  <p>The import and the app work fine when launched on localhost.</p>
  
  <p>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. </p>
  
  <p>If I would use the same line as above to import <code>City</code> model into "database_csv_imports.py" file, I would get an error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "database_csv_imports.py", line 3, in &lt;module&gt;
      from .models import City
  SystemError: Parent module '' not loaded, cannot perform relative import 
  </code></pre>
  
  <p>So I have changed relative import to absolute:</p>
  
  <pre><code>from models import City
  </code></pre>
  
  <p>This, however, throws another error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "database_csv_imports.py", line 3, in &lt;module&gt;
      from models import City
    File "/home/bart/python_projects/javascript/models.py", line 19, in &lt;module&gt;
      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.
  </code></pre>
  
  <p>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", <code>SECRET_KEY</code> is not empty, and both <code>makemigrations</code> and <code>migrate</code> are already applied. I also thought that the solution posted here: <a href="https://stackoverflow.com/questions/51081783/django-core-exceptions-appregistrynotready-apps-arent-loaded-yet-file-init">django.core.exceptions.AppRegistryNotReady: Apps aren&#39;t loaded yet. file init</a> might me an overkill in this case.</p>
  
  <p>Can someone help me fix the import error? </p>