Description
The DbConfig.ready() method in
db/apps.py
calls
check_system_user_exists()
. This queries the database (User.objects.filter(id=config("SYSTEM_ADMIN_ID")).exists()) immediately on startup. If a developer attempts to run python manage.py migrate on a fresh database, the command fails and crashes because the
user
table does not exist yet for the query to execute.
Goals
Allow python manage.py migrate to run successfully on a completely fresh, empty database.
Decouple database existence checks from the early Django app initialization phase.
Expected Outcome
Running manage.py check or manage.py migrate on a fresh setup should successfully initialize the database without throwing django.db.utils.OperationalError: no such table: user.
Acceptance Criteria
manage.py migrate completes without operational errors on a fresh database.
System admin check still functions correctly when the database is fully initialized.
Implementation Details
App registry hooks (
ready()
) should not execute database queries that assume the schema is fully migrated.
check_system_user_exists()
should be wrapped in a try...except (OperationalError, ProgrammingError): pass block, or moved to a custom management command/post-migrate signal.
Product Name
Mulearn
Project Name
mulearnbackend
Tech Skills Needed:
Python, Django
Complexity
Medium
Category
Bug
Sub Category
Backend, Configuration
Description
The DbConfig.ready() method in
db/apps.py
calls
check_system_user_exists()
. This queries the database (User.objects.filter(id=config("SYSTEM_ADMIN_ID")).exists()) immediately on startup. If a developer attempts to run python manage.py migrate on a fresh database, the command fails and crashes because the
user
table does not exist yet for the query to execute.
Goals
Allow python manage.py migrate to run successfully on a completely fresh, empty database.
Decouple database existence checks from the early Django app initialization phase.
Expected Outcome
Running manage.py check or manage.py migrate on a fresh setup should successfully initialize the database without throwing django.db.utils.OperationalError: no such table: user.
Acceptance Criteria
manage.py migrate completes without operational errors on a fresh database.
System admin check still functions correctly when the database is fully initialized.
Implementation Details
App registry hooks (
ready()
) should not execute database queries that assume the schema is fully migrated.
check_system_user_exists()
should be wrapped in a try...except (OperationalError, ProgrammingError): pass block, or moved to a custom management command/post-migrate signal.
Product Name
Mulearn
Project Name
mulearnbackend
Tech Skills Needed:
Python, Django
Complexity
Medium
Category
Bug
Sub Category
Backend, Configuration