Django console not working properly on docker

Hello! I'm working on a django project to try docker, so I've made the docker file, the docker compose, and all that stuff. The project runs fine, I can develop fine, but the problem raises when I want to use the console.

Aparently it starts ok but when I try to import stuff from my models, I'm getting this error:

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

I've noticed the command used to start the console:

/usr/local/bin/docker-compose -f /home/santiago/PycharmProjects/dockertodo/docker-compose.yml -f /home/santiago/.PyCharm2018.3/system/tmp/docker-compose.override.331.yml run --rm -p 0.0.0.0:40103:40103 web

Shoudn't be this comand somthing like:

/usr/local/bin/docker-compose -f /home/santiago/PycharmProjects/dockertodo/docker-compose.yml -f /home/santiago/.PyCharm2018.3/system/tmp/docker-compose.override.331.yml run --rm -p 0.0.0.0:40103:40103 web python manage.py shell

?

But I can't find a way to set it up. Please, can you help me?

Thank you!!

2 comments
Comment actions Permalink

Well I've found out the problem. I'm not sure why, but the console settings were different to the settings of another project where the console works well. I've copied the starting script and now it works fine.

import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)

Cheers!

0
Comment actions Permalink
Hi, Thank you for contacting JetBrains support. Your solution is correct, it's one way to import all Django modules into the shell. Another way is to use **Tools >> Run manage.py Task...** and then execute `shell` Let me know if you have any other questions.
0

Please sign in to leave a comment.