'django_celery_beat - "no such table: main.django_celery_beat_solarschedule__old" while updating "django_celery_beat_periodictask"
I'm using django + celery, when running django devserver I'm getting exception
django.db.utils.OperationalError: no such table: main.django_celery_beat_solarschedule__old
and callstack tells that it occured while doing insert into table django_celery_beat_periodictask
Database is sqlite3. Python version is 3.5.6. All migrations were applied and django_celery_beat
was added to settings
Calling code:
def register_task(task, interval=DEFAULT_TASK_INTERVAL):
logger.info("Registering periodic task %s with interval %s", task, interval)
name = "Default {}".format(task)
schedule, _ = IntervalSchedule.objects.update_or_create(
every=interval, period=IntervalSchedule.SECONDS)
PeriodicTask.objects.update_or_create(
name=name, defaults={
"interval": schedule,
"task": task
})
Actual traceback:
File "/home/zab/Git/overview-server/overview-server/src/basis/tasks/shedule.py", line 21, in register_task
"task": task
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django_celery_beat/managers.py", line 14, in update_or_create
obj, created = self.get_or_create(defaults=defaults, **kwargs)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/query.py", line 489, in get_or_create
return self._create_object_from_params(lookup, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/query.py", line 521, in _create_object_from_params
obj = self.create(**params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/query.py", line 417, in create
obj.save(force_insert=True, using=self.db)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django_celery_beat/models.py", line 316, in save
super(PeriodicTask, self).save(*args, **kwargs)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/base.py", line 759, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/base.py", line 880, in _do_insert
using=using, raw=raw)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/query.py", line 1125, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1285, in execute_sql
cursor.execute(sql, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: main.django_celery_beat_solarschedule__old
Solution 1:[1]
I suppose you didn't run migrate
and as result those tables were not created.
Run
python manage.py migrate
And make sure you added it to INSTALLED_APPS
INSTALLED_APPS = (
...,
'django_celery_beat',
)
Solution 2:[2]
The problem was in Django. Migrations were broken for new sqlite. https://code.djangoproject.com/ticket/29182
Solution 3:[3]
Bumping for recent answer. I was using the tables before they were migrated. So I commented out all the code involving beat (except installed apps), ran python manage.py migrate
fresh, then uncommented the code
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sergey Pugach |
Solution 2 | zabbius |
Solution 3 | imbes |