{"id":6602,"library":"django-upgrade","title":"django-upgrade","description":"django-upgrade is a tool that automatically upgrades your Django project code. It changes code to avoid deprecation warnings and migrates some patterns to newer Django idioms, easing the upgrade process and helping ensure your code uses the latest features. It is currently at version 1.30.0 and is actively maintained.","status":"active","version":"1.30.0","language":"python","source_language":"en","source_url":"https://github.com/adamchainz/django-upgrade","tags":["django","upgrade","refactoring","automation","code-modernization","linting"],"install":[{"cmd":"pip install django-upgrade","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[],"quickstart":{"code":"# To apply fixers for Django 4.2 to all Python files in the current directory:\ndjango-upgrade . --target-version 4.2\n\n# Or, to process a specific file and print changes to stdout (without modifying in-place):\n# django-upgrade myfile.py -","lang":"bash","description":"django-upgrade is primarily a command-line tool. You typically run it against your project's Python files, optionally specifying a target Django version. It modifies files in-place by default."},"warnings":[{"fix":"Commit pending changes, run `django-upgrade`, then meticulously review `git diff` and run your full test suite. Consider integrating it with `pre-commit` to catch new deprecations early.","message":"django-upgrade makes changes to your code in-place. It's crucial to run it on a clean Git branch and review changes carefully. Always run your test suite after applying `django-upgrade` to catch any regressions.","severity":"gotcha","affected_versions":"All"},{"message":"Some fixers (e.g., for `index_together` or `NullBooleanField`) make changes that necessitate new database migrations. After running `django-upgrade`, you may need to run `python manage.py makemigrations` and then `python manage.py migrate` to apply these schema changes.","severity":"gotcha"},{"fix":"Upgrade your Python environment to 3.10 or later before attempting to upgrade Django or use `django-upgrade` for newer Django versions.","message":"django-upgrade requires Python 3.10 or newer. When upgrading to recent Django versions (e.g., Django 5.2), ensure your Python environment meets the minimum requirements, as older Python versions are no longer supported.","severity":"breaking","affected_versions":"All versions targeting Django >= 5.2"},{"fix":"Order your tooling: run `django-upgrade` first, then formatters like Black/Ruff.","message":"django-upgrade focuses on upgrading code to avoid deprecations, not on code style. It's recommended to run `django-upgrade` *before* code formatters like Black or Ruff to avoid conflicts or reformatting changes made by `django-upgrade`.","severity":"gotcha","affected_versions":"All"},{"fix":"Always consult Django's release notes for each target version you are upgrading through, focusing on 'Backwards incompatible changes' and 'Deprecations'.","message":"While `django-upgrade` automates many code changes, it does not replace the need to read Django's official release notes, especially for major version upgrades. Manual adjustments for breaking API changes, configuration updates, or third-party package incompatibilities will still be necessary.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade your database server (e.g., PostgreSQL to 14+, MySQL to 8.0+) before or during your Django 5.2 upgrade process.","message":"When targeting Django 5.2, ensure your database backend is also compatible. Specifically, PostgreSQL 13 support is dropped (requiring 14+), and MySQL requires version 8.0+.","severity":"breaking","affected_versions":"Versions targeting Django 5.2 and later"}],"env_vars":null,"search_vec":"'1.30.0':50 'activ':53 'autom':58 'automat':11 'avoid':21 'chang':18 'code':16,19,40,60 'code-modern':59 'current':47 'deprec':22 'django':2,5,14,30,55 'django-upgrad':1,4 'eas':32 'ensur':38 'featur':44 'help':37 'idiom':31 'latest':43 'lint':62 'maintain':54 'migrat':25 'modern':61 'newer':29 'pattern':27 'process':35 'project':15 'refactor':57 'tool':9 'upgrad':3,6,12,34,56 'use':41 'version':49 'warn':23","created_at":"2026-04-15T18:34:57.589907+00:00","updated_at":"2026-04-16T14:36:39.187407+00:00","problems":[{"fix":"Install the package using pip: `pip install django-upgrade`","cause":"The `django-upgrade` package is not installed in the active Python environment, or the environment where it's installed is not the one being used.","error":"ModuleNotFoundError: No module named 'django_upgrade'"},{"fix":"Run `django-upgrade` to automatically add `on_delete` arguments, typically `models.CASCADE`, `models.SET_NULL`, or `models.PROTECT`, to your ForeignKey and OneToOneField definitions: `django-upgrade .`","cause":"When upgrading to Django 2.0 and later, `on_delete` is a mandatory argument for `ForeignKey` and `OneToOneField` definitions in Django models, which was not strictly enforced in earlier versions.","error":"missing 1 required positional argument: 'on_delete'"},{"fix":"Run `django-upgrade` to automatically add `app_name` attributes to your `urls.py` files or pass the `app_name` explicitly in the `include()` call: `django-upgrade .`","cause":"From Django 2.0 onwards, if you use the `include()` function with a namespace in your `urls.py` without also defining an `app_name` in the included URL patterns, Django raises this error to ensure clarity in URL resolution.","error":"Specifying a namespace in include() without providing an app_name"},{"fix":"Run `django-upgrade` to automatically replace `from django.utils.timezone import utc` with `from datetime import timezone; utc = timezone.utc` or similar fixes: `django-upgrade .`","cause":"The `utc` constant in `django.utils.timezone` was deprecated in Django 4.1 and removed in later versions, requiring the use of `datetime.timezone.utc` instead.","error":"ImportError: cannot import name 'utc' from 'django.utils.timezone'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"django-upgrade","cli_version":"1.30.0","type":"library","homepage":null,"github":"https://github.com/adamchainz/django-upgrade","docs":"https://django-upgrade.readthedocs.io/","changelog":"https://django-upgrade.readthedocs.io/en/latest/changelog.html","pypi":"https://pypi.org/project/django-upgrade/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-04-15","next_check":"2026-07-14","install_tag":null}}