I added some signal receivers to my code and everything was working fine, until I pushed it to version control and the CI/CD pipeline failed. On trying to migrate, it would complain with:
django.db.utils.OperationalError: no such table: badges_badge
But the migrations were working on my machine!
The CI/CD starts from scratch though, so I tried deleting my db.sqlite3
locally, then tried to re-migrate with python manage.py migrate
:
django.db.utils.OperationalError: no such table: badges_badge
So migrating from an existing db worked, but not from a new one.
My signals.py
:
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
from badges.badge_stuff import badges
@receiver(post_save)
def update_badges(sender, **kwargs):
for badge in badges:
badge.update()
My apps.py
:
from django.apps import AppConfig
class BadgesConfig(AppConfig):
name = 'badges'
def ready(self):
# Register signal listeners.
from . import signals
Why would it work with an existing db, but not when initialising it? How to fix this?