Raku
Raku

Reputation: 37

Django shell does not let me query models

I am trying to query my customized user model "RmkUser" through the django shell, but it keeps raising an error when I try to command "from models import RmkUser":

RuntimeError: Model class models.RmkUser doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

I am not sure why it does this, nor was I able to find out through other posts. I saw that there are a lot of posts which show problems with this error, too, but I can't find a solution for my specific case.

I don't understand why django asks me to declare my customized user model "RmkUser" under INSTALLED_APPS. After all, its a model, not an app. My app (as opposed to the "RmkUser" model), however, is entered under INSTALLED_APPS and it also has an app_label. Also, I did set AUTH_USER_MODEL to my customized user model. Not only that, but my site is actually running completely fine when I "python manage.py runserver". I can create new users, log in, etc, no problem.

Does anybody know how I can get the shell to let me query the "RmkUser" model?

Thanks in advance!

Upvotes: 0

Views: 526

Answers (2)

Eby Sofyan
Eby Sofyan

Reputation: 464

I suggest you to use shell_plus from django_extension. It will load your models at the first time running. Simple to use, just run the below command

python manage.py shell_plus

Or you can see the detail here

Upvotes: 2

Diego Magalhães
Diego Magalhães

Reputation: 1762

To import a custom model, you need to specify which app it will come, try:

from yourapp.models import RmkUser

Upvotes: 3

Related Questions