Django 1.9.7 in VS2015 Django Shell django.core.exceptions.AppRegistryNotReady:尚未加载应用程序

时间:2016-06-14 05:12:09

标签: python django python-3.x visual-studio-2015 django-1.9

我是Django的新手。我正在关注MVA的一个教程,我遇到了一个模块,其中Django Shell用于从models.py文件导入表(类)并对其使用查询。当我尝试使用代码

导入表格时
    from app.models import Artist

结果是:

    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.

我完全难过,因为我正在按照教程写信并且不知道如何通过它。与教程的唯一区别是python和Django的版本

在我尝试此代码之前,我只在models.py文件中添加了2个类,并在命令提示符下运行以下命令:

    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

正在使用的数据库是sqlite3。 任何帮助将非常感激。在此先感谢!

1 个答案:

答案 0 :(得分:0)

dmitryro发布的解决方案使用Visual Studio中的Django管理控制台运行Python 3.4.4和Django 1.9.7

  

&gt;&gt;&gt;导入django
  &GT;&GT;&GT; django.setup()