Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django 1.7rc3 and celery 3.13 - AppRegistryNotReady

This does not work for me

$> cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"

django 1.7rc3
celery 3.1.13
python 2.7

I attempt to run

celery worker -A <project_name>

and I get

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

The runserver command works fine so I don't think it has to do with my settings?

python manage.py runserver 0.0.0.0:8080

I've double checked celery.py and confirm it has the correct values for the following lines:

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')

app = Celery('proj')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')

Is there something else i should be doing?

like image 779
w-- Avatar asked Aug 25 '14 20:08

w--


1 Answers

Django 1.7 now requires a different initialization for standalone scripts. When running outside the manage.py context, you now need to include:

import django
django.setup()

Try adding it before the app = Celery('proj') in your script.

like image 110
Steve Avatar answered Sep 23 '22 10:09

Steve