0

I used to load models in Python shell in PyCharm with no error before, but now it through this error

Traceback (most recent call last):
  File "<input>", line 12, in <module>
  File "C:\...\lib\site-packages\django\db\models\base.py", line 112, in __new__
    raise RuntimeError(
RuntimeError: Model class __main__.Source doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

I checked similar questions such as this and this and followed the proposed answers with no success. Funny thing is that python manage.py runserver doesn't through any error and website load smoothly.

The only change to my environment is that update for windows I got yesterday.

I already have app name for all of my apps, set the DJANGO_SETTINGS_MODULE and all imports are absolute.

Mehdi Zare
  • 1,221
  • 1
  • 16
  • 32
  • If you are deploying to a remote server, try uploading your entire django project. If you are not deploying to a remote server you might want to remove all your `*pyc` files. – Red Cricket Mar 15 '20 at 15:29
  • It works just fine when I deploy it to a remote server, it also works fine with py manage.py runserver command. The only problem is when I'm trying to run it in python shell for debugging. – Mehdi Zare Mar 16 '20 at 00:52
  • How are you starting you python console? – Red Cricket Mar 16 '20 at 01:00
  • @RedCricket I'm using PyCharm. Probably it's a mistake after long hours of trying to solve something that is not a real problem. I tried to load the model definition and got this error. But then I tried ``` from appname.models import modelname ``` and it worked. sorry for posting a wrong question! – Mehdi Zare Mar 16 '20 at 01:14

0 Answers0