Django Version Upgrade

Django Version Upgrade

Upgrading to the most recent Django version offers the following advantages, despite occasionally being a difficult process:

  • Improvements and new features are included.
  • The bugs are fixed. 
  • Security updates for older Django versions will eventually stop being released.
  • By keeping your code base current, upgrading as soon as a new Django release is available makes subsequent upgrades less painful.

Check the supported version: Supported version

Read the release note:

Before you attempt an upgrade of a particular Django version, it is prudent to review the release notes for the version that you are upgrading to.

Follow the Divide and conquer Approach:

Divide and conquer is the best piece of advice we can give you. That entails upgrading from the existing version to the most stable version that django supports, then moving up to higher versions step by step until you reach your desired version. In our case, we have migrated from Django version 2.2 to 3.2 to 4.1 to 4.2, etc.

Unit Test Cases:

When attempting upgrades of any kind, unit tests are essential. Without unit tests, the only option for exercising the code is time-consuming manual testing. 

In fact, don’t upgrade if there aren’t any unit tests!  It would be better to postpone the upgrade and include more unit tests that at least cover half of the project.

Recently we got one request from one of our clients to migrate the django version from 2.2.18 to the latest version 4.2.1. We followed the “Divide and conquer” approach to achieve this. 

Our first approach was migrate the project from django 2.2 to 3.2.15 stable django version supported by Django with securities

Firstly we review the release notes of the version, fix all deprecation warnings and updated test coverage and then we update the version of Django using pip-tools

After that we upgraded the 3.2.15 to 4.1.1 Django version

Let us explain a few changes have been made in the provided codebase to achieve successful versioning and stable functionality. These changes are subjected to the codebase and used packages:

  1. Adding base directory to configuration in with dot operator
  2. Addition of new Fields in models like models.JSONField 
  3. Using django packages like two factor authentication (django-two-factor-auth)
    1. Included tags file
    2. Loading tags file in the html pages
    3. Importing some of the plugins from the package
  4. Some functions has been depreciated and new functions for the same has been implemented like:
    1. self.request.is_ajax() has been updated to self.request.META.get(‘HTTP_X_REQUESTED_WITH’) == ‘XMLHttpRequest’
    2. django.utils.translation import ugettext_lazy changed to django.utils.translation import gettext_lazy, etc

Note: The changes can be different as per your codebase. We are just trying to highlight what all changes we did to achieve the django version migration from 2.2 to 4.2.1


Although upgrading software can be intimidating, there is never a better time to do it than right now because waiting until later will only make it harder and more risky. 

It is easier to develop and deploy software when using tools like source control and Docker, which help minimise environment variations. 

Last but not least, unit test cases are a huge help in preventing errors during routine software development and upgrades.

If you need help keeping your projects up-to-date, reach out to us. We are here to help.

More Details: How to upgrade Django to a newer version¶

Leave a Comment

Your email address will not be published.