Django 2.0环境中Celery队列异常问题求助(生产环境待迁移)
Hey there, let's work through getting your production Django 1.11 setup migrated to Django 2.0 while resolving the dependency issues in your dev environment. Here's a practical, step-by-step plan:
1. Align Dependency Versions for Compatibility
First, the "异常" in your dev environment is almost certainly due to minor version mismatches between packages that don't play well with Django 2.0.3. Let's lock in a set of dependencies that work reliably with Django 2.0 and match your production stack as much as possible:
# Compatible requirements for Django 2.0.x amqp==2.2.2 django==2.0.13 # Use the latest stable patch in the 2.0 series for security fixes celery==4.1.0 django-celery-beat==1.1.1 # This version explicitly supports Django 2.0 django-celery-monitor==1.1.2 kombu==4.1.0 redis==2.10.6
- Why Django 2.0.13 instead of 2.0.3? It includes critical bug fixes and security patches that your dev/prod environments should have.
- Celery 4.1.0 is fully compatible with Django 2.0, so no need to upgrade that unless you hit specific bugs.
2. Production Migration Step-by-Step
Always prioritize backups before making changes to production:
- Backup everything:
- Dump your database (e.g.,
pg_dump your_prod_db > prod_backup.sqlfor PostgreSQL, or equivalent for your DB) - Archive your current codebase and virtual environment so you can roll back if needed
- Dump your database (e.g.,
- Upgrade Django in production:
- Activate your production virtual environment and run:
pip install django==2.0.13 - Run
python manage.py checkto catch Django 2.0 compatibility issues (common fixes include replacingurl()withpath()/re_path()in your urls.py, adding expliciton_deleteparameters to ForeignKeys, etc.)
- Activate your production virtual environment and run:
- Validate Celery and Plugin Functionality:
- Restart your Celery worker:
celery -A your_project_name worker --loglevel=infoand check for startup errors - Restart Celery Beat (if using django-celery-beat):
celery -A your_project_name beat --loglevel=infoand verify scheduled tasks trigger as expected - Confirm django-celery-monitor loads without errors by accessing its admin/monitor views
- Restart your Celery worker:
- Run Database Migrations:
- Execute
python manage.py makemigrations(only if you’ve made model changes to support Django 2.0) - Run
python manage.py migrateto apply any Django 2.0-specific schema updates
- Execute
- Full Functional Testing:
- Test all core features, especially those relying on Celery async tasks, to ensure jobs submit, execute, and return results correctly
- Verify admin functionality and any custom integrations work as expected
3. Fixing the Dev Environment Requirements Error
If your dev environment is throwing errors with the current requirements, try these fixes:
- Reset your virtual environment:
Fresh environments often resolve hidden dependency conflicts.deactivate rm -rf your_dev_venv python -m venv your_dev_venv source your_dev_venv/bin/activate pip install -r requirements.txt - Pin dependencies one-by-one: If the error persists, install packages individually (start with Django, then Celery, then the celery plugins) to identify which package is causing the conflict.
- Check for deprecated APIs: Ensure your dev codebase has already been updated to Django 2.0 standards (same fixes you applied to production) — outdated code can trigger misleading dependency errors.
内容的提问来源于stack exchange,提问作者Jonathan DEKHTIAR
相关产品推荐
相关产品推荐

