diff --git a/kolibri/core/device/migrations/0019_syncqueue_and_status.py b/kolibri/core/device/migrations/0019_syncqueue_and_status.py index 5169bb8748b..cb0f38b8e34 100644 --- a/kolibri/core/device/migrations/0019_syncqueue_and_status.py +++ b/kolibri/core/device/migrations/0019_syncqueue_and_status.py @@ -4,7 +4,7 @@ import django.db.models.deletion import morango.models.fields.uuids -from django.conf import settings +from django.db import connection from django.db import migrations from django.db import models @@ -20,6 +20,14 @@ class Migration(migrations.Migration): model_name="usersyncstatus", name="queued", ), + migrations.RunSQL( + [ + "DELETE FROM device_syncqueue;" + if "sqlite" in connection.vendor + else "TRUNCATE TABLE device_syncqueue;" + ], + hints={"is_syncqueue": True}, + ), migrations.AddField( model_name="syncqueue", name="attempts", diff --git a/kolibri/core/device/models.py b/kolibri/core/device/models.py index a030ab6555b..9b6672c536d 100644 --- a/kolibri/core/device/models.py +++ b/kolibri/core/device/models.py @@ -483,9 +483,8 @@ def allow_relation(self, obj1, obj2, **hints): def allow_migrate(self, db, app_label, model_name=None, **hints): """Ensure that the SyncQueue models get created on the right database.""" - if ( - app_label == SyncQueue._meta.app_label - and model_name == SyncQueue._meta.model_name + if app_label == SyncQueue._meta.app_label and ( + model_name == SyncQueue._meta.model_name or hints.get("is_syncqueue") ): # The SyncQueue model should be migrated only on the SYNC_QUEUE database. return db == SYNC_QUEUE