Answers for "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.."

0

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': (),
    },
}
Posted by: Guest on May-04-2021

Code answers related to "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.."

Python Answers by Framework

Browse Popular Code Answers by Language