Koed00 / django-q

A multiprocessing distributed task queue for Django
https://django-q.readthedocs.org
MIT License
1.83k stars 285 forks source link

post-upgrade - no such column: django_q_schedule #634

Open smierd opened 2 years ago

smierd commented 2 years ago

Hello,

I am getting the following error after upgrading my system no such column: django_q_schedule.cluster

I have made no other code changes. When trying to open the Scheduled Tasks from the admin panel, I get the error above. The qcluster console shows the error every 30s, in the shell, trying to run

from django_q.models import * Schedule.objects.all()

sqlite3.OperationalError: no such column: django_q_schedule.cluster

It stopped working after my upgrades but I did them all together (rookie mistake) so I am not sure which is the cause. Wondering if I need to roll back of if there's an easy solution.

Thank you!

smierd commented 2 years ago

I downgraded django-q back to 1.3.5 and everything is working again. Not sure what the issue is exactly.

youri-ds commented 2 years ago

Same issue here with postgres, the upgrade from 1.3.5 to 1.3.9 has failed but the issue starts with 1.3.6

I suspect the PR #555 because of cluster field.

And the issue is reported in #610 as well.

python manage.py migrate is reporting the same error "column django_q_schedule.cluster does not exist"

adamchainz commented 2 years ago

PR #555 includes a migration file. After updating to the latest version, did you run ./manage.py migrate?

@youri-ds if you're having a problem during migrate, it's possibly due to trying to use the schedule() function or Schedule model during import time. Try moving that code to run later, for example during a custom qcluster management command. Here's an example I just wrote for a project:

from django_q.management.commands.qcluster import Command as BaseCommand
from django_q.models import Schedule

from example import tasks

class Command(BaseCommand):
    def handle(self, *args, **kwargs):
        ensure_schedule_updated()
        super().handle(*args, **kwargs)

def ensure_schedule_updated():
    def path(func):
        return f"{func.__module__}.{func.__name__}"

    Schedule.objects.update_or_create(
        name="run_debug_print",
        defaults={
            "func": path(tasks.debug_print),
            "schedule_type": Schedule.MINUTES,
            "minutes": 5,
        },
    )
youri-ds commented 2 years ago

@youri-ds if you're having a problem during migrate, it's possibly due to trying to use the schedule() function or Schedule model during import time. Try moving that code to run later, for example during a custom qcluster management command. Here's an example I just wrote for a project:

Hi Adam, I think your are right because I have some initialization code. I will upgrade and test your code when I have the time. Thank you.