How to Upgrade from Django 5.1 to Django 5.2 (LTS)

Published on 13 Dec 2025Development
image
Photo by Faisal on Unsplash

Upgrading to Django 5.2 is a highly recommended move for developers seeking stability. As a Long Term Support (LTS) version, Django 5.2 will receive security patches and critical bug fixes until April 2028. Since version 5.1 reached its end-of-life in December 2025, moving to 5.2 is essential for keeping your application secure.

Step 1: Check Python Compatibility

Before upgrading, ensure your environment is running a supported Python version. Django 5.2 supports:

  • Python 3.10
  • Python 3.11
  • Python 3.12
  • Python 3.13

Step 2: Check for Deprecation Warnings

Run your current Django 5.1 project with the warnings flag enabled. This identifies code patterns that will be removed or changed in version 5.2.

python -Wa manage.py test

Address any "RemovedInDjango52Warning" messages before proceeding to the next step.

Step 3: Update the Django Package

Depending on how you manage your project dependencies, use one of the following commands to install Django 5.2. Using the version-specific constraint ensures you stay within the LTS release.

Option A: Using Standard Pip

If you use a requirements.txt file, run this command to upgrade your environment, then manually update your requirements file:

python -m pip install -U "Django>=5.2,<5.3"

Option B: Using Pipenv (Recommended for Applications)

If you use Pipenv, this command will upgrade your virtual environment and automatically update your Pipfile and Pipfile.lock:

pipenv install "django>=5.2,<5.3"

Note: If you previously used pip install inside a Pipenv project, your Pipfile may still show the old version. Running the pipenv install command above will fix this inconsistency.

Step 4: Update Third-Party Dependencies

Libraries like Django Rest Framework or Django Filter may require updates to remain compatible with the 5.2 core. Check for outdated packages using:

pip list --outdated

Step 5: Run Database Migrations

Even if your models haven't changed, Django's internal apps often require migration updates between versions.

python manage.py migrate

Step 6: Verify and Test

Confirm the installation was successful by checking the version and running your test suite:

python -m django --version
python manage.py test

Step 7: Sync Your Dependency Files

After upgrading the code, you must ensure your project's tracking files match what is actually installed. If you skip this, your production server or teammates will end up with the wrong version.

If you use requirements.txt

Standard pip does not update your text file automatically. You must manually "freeze" the new state of your environment:

python -m pip freeze > requirements.txt

If you use Pipenv

If you used pip install earlier instead of pipenv install, your Pipfile is now out of sync. You should run the update command to synchronize your lock file and verify your dependencies:

pipenv update

To check if any other sub-dependencies are still outdated, run:

pipenv update --outdated

Key Changes in Django 5.2

  • Composite Primary Keys: Enhanced support for models that require multiple fields to define a primary key.
  • Admin Facet Counts: The admin sidebar now displays counts for filters by default. If this impacts performance, it can be toggled off using "show_facets = False".
  • Validation Improvements: Better handling of UniqueConstraint and CheckConstraint during form validation.

Meow! AI Assistance Note

This post was created with the assistance of Gemini AI and ChatGPT.
It is shared for informational purposes only and is not intended to mislead, cause harm, or misrepresent facts. While efforts have been made to ensure accuracy, readers are encouraged to verify information independently. Portions of the content may not be entirely original.

image
Photo by Yibo Wei on Unsplash