Compose-frontend does not access the database

I am trying to run the following command:

python3 run.py --compose-frontend run kpi python ./manage.py shell

but when I run the following command for example:

User.objects.count()

I get this message:

  File "/opt/venv/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)

django.db.utils.OperationalError: no such table: auth_user

Which clearly indicates that I am not running with the correct env variables that allow me to connect to the Postgresql database.
How can I run a shell and connect to the already running db?

I have understood that I had to specify the database so:

python3 run.py --compose-frontend run --rm kpi django-admin  loaddata --database=kobocat /srv/src/kpi/media/dump_users.json

now works but I got this error:

raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

Does anybody know a better way to use datadumps to move databases and tables?

Hi @paoloc68,

I think you are facing this issue https://github.com/kobotoolbox/kobo-docker/issues/264.
As a workaround. You can enter the container (./run.py -cf exec kpi bash) and then run ./manage.py shell_plus

Otherwise you can export DATABASE_URL within the command

./run.py -e DATABASE_URL=postgis://<username>:<password>@postgres.kobo.private:5432/koboform --rm kpi python ./manage.py shell_plus

Please update postgres.kobo.private and koboform with your settings.

3 Likes