1

I am using Django 2.0.3 version with python 3.4. I am following simple Polls Tutorial and I am getting following error in models file.

Errors in polls/models.py:

Traceback (most recent call last):
  File "E:\Mysite\mysite\polls\models.py", line 4, in <module>
    class Questions(models.Model):
  File "C:\Python34\lib\site-packages\django\db\models\base.py", line 100, in __new__
    app_config = apps.get_containing_app_config(module)
  File "C:\Python34\lib\site-packages\django\apps\registry.py", line 244, in get_containing_app_config
    self.check_apps_ready()
  File "C:\Python34\lib\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.

Then I searched the internet due to which I checked wsgi file and there also I got ImportError. I didn't make any changes in wsgi file.

Errors in wsgi:

Traceback (most recent call last):
  File "E:\Mysite\mysite\mysite\wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "C:\Python34\lib\site-packages\django\core\wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "C:\Python34\lib\site-packages\django\__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
    self._setup(name)
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 106, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Python34\lib\importlib\__init__.py", line 104, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2189, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2201, in _find_and_load_unlocked
ImportError: No module named 'mysite'

models.py

from django.db import models


class Questions(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')


class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASACDE)
    choice_text = models.CharFeild(max_length=200)
    votes = models.IntegerField(default=0)

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = get_wsgi_application()

Directory structure

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
    polls/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    urls.py
    views.py

Please let me know why I am getting these errors. Thankyou

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Alok Ramteke
  • 123
  • 4
  • 11
  • Please copy and paste the traceback instead of linking to an image. What command are you running and which directory are you running it from? – Alasdair Apr 10 '18 at 12:11
  • Maybe this can help you https://stackoverflow.com/questions/25680803/django-1-7-upgrade-error-appregistrynotready-models-arent-loaded-yet/39779915#39779915 – julian salas Apr 10 '18 at 13:46
  • I followed the link(https://stackoverflow.com/questions/25680803/django-1-7-upgrade-error-appregistrynotready-models-arent-loaded-yet/39779915#39779915), but it didn't help me – Alok Ramteke Apr 10 '18 at 14:00
  • @Alasdair Now I give detailed information about my problem. Please do check again. – Alok Ramteke Apr 10 '18 at 14:03
  • Please double check the indentation of your directory structure. You don't need `django.setup()` unless you are using standalone scripts. Remove it. What commands are you running to get those errors? – Alasdair Apr 10 '18 at 14:07
  • @Alasdair I didn't use django.setup() anywhere in my code. I am using the Sublime text editor to edit code and to check error I am using Ctrl+B(Build). am I getting these errors due to build? Please let me know. – Alok Ramteke Apr 10 '18 at 14:20
  • The suggestion from Julian was to add `django.setup()`, that's why I said to remove it. I would try running the commands directly in your terminal, e.g. `python manage runserver`. That way you can narrow down whether it's a problem in your code or Sublime config, – Alasdair Apr 10 '18 at 14:30

0 Answers0