upgrade-version.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ===================================
  2. Upgrading Django to a newer version
  3. ===================================
  4. While it can be a complex process at times, upgrading to the latest Django
  5. version has several benefits:
  6. * New features and improvements are added.
  7. * Bugs are fixed.
  8. * Older version of Django will eventually no longer receive security updates.
  9. (see :ref:`supported-versions-policy`).
  10. * Upgrading as each new Django release is available makes future upgrades less
  11. painful by keeping your code base up to date.
  12. Here are some things to consider to help make your upgrade process as smooth as
  13. possible.
  14. Required Reading
  15. ================
  16. If it's your first time doing an upgrade, it is useful to read the :doc:`guide
  17. on the different release processes </internals/release-process>`.
  18. Afterwards, you should familiarize yourself with the changes that were made in
  19. the new Django version(s):
  20. * Read the :doc:`release notes </releases/index>` for each 'final' release from
  21. the one after your current Django version, up to and including the version to
  22. which you plan to upgrade.
  23. * Look at the :doc:`deprecation timeline</internals/deprecation>` for the
  24. relevant versions.
  25. Pay particular attention to backwards incompatible changes to get a clear idea
  26. of what will be needed for a successful upgrade.
  27. If you're upgrading through more than one feature version (e.g. A.B to A.B+2),
  28. it's usually easier to upgrade through each feature release incrementally
  29. (A.B to A.B+1 to A.B+2) rather than to make all the changes for each feature
  30. release at once. For each feature release, use the latest patch release (A.B.C).
  31. The same incremental upgrade approach is recommended when upgrading from one
  32. LTS to the next.
  33. Dependencies
  34. ============
  35. In most cases it will be necessary to upgrade to the latest version of your
  36. Django-related dependencies as well. If the Django version was recently
  37. released or if some of your dependencies are not well-maintained, some of your
  38. dependencies may not yet support the new Django version. In these cases you may
  39. have to wait until new versions of your dependencies are released.
  40. Resolving deprecation warnings
  41. ==============================
  42. Before upgrading, it's a good idea to resolve any deprecation warnings raised
  43. by your project while using your current version of Django. Fixing these
  44. warnings before upgrading ensures that you're informed about areas of the code
  45. that need altering.
  46. In Python, deprecation warnings are silenced by default. You must turn them on
  47. using the ``-Wall`` Python command line option or the :envvar:`PYTHONWARNINGS`
  48. environment variable. For example, to show warnings while running tests:
  49. .. console::
  50. $ python -Wall manage.py test
  51. If you're not using the Django test runner, you may need to also ensure that
  52. any console output is not captured which would hide deprecation warnings. For
  53. example, if you use `py.test`:
  54. .. code-block:: console
  55. $ PYTHONWARNINGS=all py.test tests --capture=no
  56. Resolve any deprecation warnings with your current version of Django before
  57. continuing the upgrade process.
  58. Third party applications might use deprecated APIs in order to support multiple
  59. versions of Django, so deprecation warnings in packages you've installed don't
  60. necessarily indicate a problem. If a package doesn't support the latest version
  61. of Django, consider raising an issue or sending a pull request for it.
  62. Installation
  63. ============
  64. Once you're ready, it is time to :doc:`install the new Django version
  65. </topics/install>`. If you are using virtualenv_ and it is a major upgrade, you
  66. might want to set up a new environment with all the dependencies first.
  67. If you installed Django with pip_, you can use the ``--upgrade`` or ``-U`` flag:
  68. .. console::
  69. $ pip install -U Django
  70. .. _pip: https://pip.pypa.io/
  71. .. _virtualenv: https://virtualenv.pypa.io/
  72. Testing
  73. =======
  74. When the new environment is set up, :doc:`run the full test suite
  75. </topics/testing/overview>` for your application. Again, it's useful to turn
  76. on deprecation warnings on so they're shown in the test output (you can also
  77. use the flag if you test your app manually using ``manage.py runserver``):
  78. .. console::
  79. $ python -Wall manage.py test
  80. After you have run the tests, fix any failures. While you have the release
  81. notes fresh in your mind, it may also be a good time to take advantage of new
  82. features in Django by refactoring your code to eliminate any deprecation
  83. warnings.
  84. Deployment
  85. ==========
  86. When you are sufficiently confident your app works with the new version of
  87. Django, you're ready to go ahead and :doc:`deploy </howto/deployment/index>`
  88. your upgraded Django project.
  89. If you are using caching provided by Django, you should consider clearing your
  90. cache after upgrading. Otherwise you may run into problems, for example, if you
  91. are caching pickled objects as these objects are not guaranteed to be
  92. pickle-compatible across Django versions. A past instance of incompatibility
  93. was caching pickled :class:`~django.http.HttpResponse` objects, either
  94. directly or indirectly via the :func:`~django.views.decorators.cache.cache_page`
  95. decorator.