wagtail / bakerydemo

Next generation Wagtail demo, born in Reykjavik

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker setup failing with django.db.utils.OperationalError: no such table: wagtailcore_site

gasman opened this issue · comments

Following the Docker installation instructions at https://github.com/wagtail/bakerydemo#setup-with-docker fails on the docker compose run app /venv/bin/python manage.py load_initial_data step with the error

django.db.utils.OperationalError: no such table: wagtailcore_site
[+] Running 2/0
 ⠿ Container bakerydemo-redis-1  Running                                                                                                                                    0.0s
 ⠿ Container bakerydemo-db-1     Running                                                                                                                                    0.0s
Postgres is up - continuing
/venv/lib/python3.9/site-packages/dotenv.py:56: UserWarning: Not reading /code/.env - it doesn't exist.
  warnings.warn("Not reading {0} - it doesn't exist.".format(dotenv))
Copying media files to configured storage...
Traceback (most recent call last):
  File "/venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/venv/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 357, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: wagtailcore_site

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/code/manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/venv/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/venv/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/code/bakerydemo/base/management/commands/load_initial_data.py", line 35, in handle
    if Site.objects.filter(hostname="localhost").exists():
  File "/venv/lib/python3.9/site-packages/django/db/models/query.py", line 1226, in exists
    return self.query.has_results(using=self.db)
  File "/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 592, in has_results
    return compiler.has_results()
  File "/venv/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1366, in has_results
    return bool(self.execute_sql(SINGLE))
  File "/venv/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1398, in execute_sql
    cursor.execute(sql, params)
  File "/venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/venv/lib/python3.9/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/venv/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 357, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: wagtailcore_site

Waiting 10 seconds and retrying (as advised by the docs) doesn't help.

This seems to have started from commit 7486296. Notably, running docker compose run app /venv/bin/python manage.py dbshell shows that it's attempting to use sqlite as the database - in 086170f (prior to the updates from #393) it was using Postgres. I suspect that the changes to how settings files are imported caused us to switch from the production environment (which picks up database config from dj_database_url) to dev, and 7486296 made the sqlite database file non-persistent between commands.

Fixed in #411