Search code examples
pythondjangopython-3.xvisual-studio-2015django-1.9

Django 1.9.7 in VS2015 Django Shell django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet


I'm a newcomer to Django. I was following a tutorial from MVA and i got stuck on one module where Django Shell was to be used to import a table(class) from the models.py file and use queries on it. When i try to import the table using the code

    from app.models import Artist

It resulted in:

    Python 3.5 interactive window [PTVS 2.2.40315.00-14.0]
    Type $help for a list of commands.
    Starting Django 1.9.7 shell
    >>> from app.models import Artist
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File ".\app\models.py", line 8, in <module>
        class Artist(models.Model):
      File "C:\Users\Aditya\documents\visual studio 2015\Projects\MVAPracticeDjangoWebProject1\MVAPracticeDjangoWebProject1\django_pyth_env\lib\site-packages\django\db\models\base.py", line 94, in __new__
        app_config = apps.get_containing_app_config(module)
      File "C:\Users\Aditya\documents\visual studio 2015\Projects\MVAPracticeDjangoWebProject1\MVAPracticeDjangoWebProject1\django_pyth_env\lib\site-packages\django\apps\registry.py", line 239, in get_containing_app_config
        self.check_apps_ready()
      File "C:\Users\Aditya\documents\visual studio 2015\Projects\MVAPracticeDjangoWebProject1\MVAPracticeDjangoWebProject1\django_pyth_env\lib\site-packages\django\apps\registry.py", line 124, in check_apps_ready
        raise AppRegistryNotReady("Apps aren't loaded yet.")
    django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

I'm totally stumped as i was following the tutorial to the letter and have no clue how to get past it. The only differences with the tutorial were the versions of python and Django

Before i tried this code i only added 2 classes to the models.py file and run the following in command prompt:

    C:\Users\Aditya\documents\visual studio 2015\Projects\MVAPracticeDjangoWebProject1\MVAPracticeDjangoWebProject1>python manage.py makemigrations --name initial app
    Migrations for 'app':
      0001_initial.py:
        - Create model Album
        - Create model Artist
        - Add field album_artist to album

    C:\Users\Aditya\documents\visual studio 2015\Projects\MVAPracticeDjangoWebProject1\MVAPracticeDjangoWebProject1>python manage.py migrate
    Operations to perform:
      Apply all migrations: contenttypes, sessions, auth, admin, app
    Running migrations:
      Rendering model states... DONE
      Applying app.0001_initial... OK

The database in use is sqlite3. Any help would be much appreciated. Thanks in Advance!


Solution

  • The solution posted by dmitryro worked for me using the Django Management Console in VisualStudio Running Python 3.4.4 and Django 1.9.7

    >>>import django
    >>>django.setup()