Am a new Django User and am finding difficulties making a query to my database

31 views
Skip to first unread message

Abdul-Waris Dawuda

unread,
Sep 13, 2017, 7:13:32 AM9/13/17
to Django users
Hello Everyone
 
Am new to Django and am currently facing a problem trying to import a class from my models.

i get this error when i try to do that from the Shell. I am using Visual Studio. i get this problem when i run my command to import;

>>> 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\Abdul-Waris\source\repos\DjangoWebProject2\DjangoWebProject2\env\lib\site-packages\django\db\models\base.py", line 110, in __new__
    app_config = apps.get_containing_app_config(module)
  File "C:\Users\Abdul-Waris\source\repos\DjangoWebProject2\DjangoWebProject2\env\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
    self.check_apps_ready()
  File "C:\Users\Abdul-Waris\source\repos\DjangoWebProject2\DjangoWebProject2\env\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Oladipupo Elegbede

unread,
Sep 13, 2017, 7:17:28 AM9/13/17
to django...@googlegroups.com
Did you include your app in the installed apps list in your settings.py file?

Did you do the makemigration and migration after creating the model?

Check these two steps and then try again. That's what I'm suspecting given the error trace.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7b86f648-798a-4cb5-8fb9-cf2a7db83dd5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Melvyn Sopacua

unread,
Sep 13, 2017, 9:07:26 AM9/13/17
to django...@googlegroups.com
Well, the simplest answer is you used the python shell and not the
django shell via `python manage.py shell`.
The app not being in installed apps gives a slightly different error
and migrations have little to do with it as importing a model doesn't
hit the database.

So simply use `python manage.py shell`. Or do this:

% env DJANGO_SETTINGS_MODULE='myapp.settings' python
Python 3.6.2+ (heads/3.6:95b16a9, Jul 27 2017, 14:00:36)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from kernel.models import Gender
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/melvyn/hg/myapp/kernel/models/__init__.py", line 10, in <module>
from kernel.fields import *
File "/home/melvyn/hg/myapp/kernel/fields.py", line 8, in <module>
from kernel.models.base import Country
File "/home/melvyn/hg/myapp/kernel/models/base.py", line 8, in <module>
class UniquelyNamedDutchEnglishItem(models.Model):
File "/home/melvyn/.local/py-env/myapp/lib/python3.6/site-packages/django/db/models/base.py",
line 110, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/melvyn/.local/py-env/myapp/lib/python3.6/site-packages/django/apps/registry.py",
line 247, in get_containing_app_config
self.check_apps_ready()
File "/home/melvyn/.local/py-env/myapp/lib/python3.6/site-packages/django/apps/registry.py",
line 125, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
>>> import django
>>> django.setup()
>>> from kernel.models import Gender
>>> # tada!
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/7b86f648-798a-4cb5-8fb9-cf2a7db83dd5%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHjgLX5kzWiAsmEn%2BweL4D-TqezET0QMa-EBTXQH-U0%2BjKRg9Q%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Melvyn Sopacua
Reply all
Reply to author
Forward
0 new messages