django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 2880151263712 and this is thread id 2880228687712. code example
Example: django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 140423029811616 and this is thread id 140422957233632..
from __future__ import absolute_import, unicode_literals
from myproject.celery import app
from celery.utils.log import get_task_logger
from celery.schedules import crontab
from django.core import management
@app.task
def db_backup_to_dropbox():
management.call_command('dbbackup', interactive=False)
app.conf.beat_schedule = {
'backup-every-second': {
'task': 'core.tasks.db_backup_to_dropbox',
'schedule': crontab(minute='*/1'),
'args': (),
},
}