upgrade-version.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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:`backwards-compatibility-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. Dependencies
  28. ============
  29. In most cases it will be necessary to upgrade to the latest version of your
  30. Django-related dependencies as well. If the Django version was recently
  31. released or if some of your dependencies are not well-maintained, some of your
  32. dependencies may not yet support the new Django version. In these cases you may
  33. have to wait until new versions of your dependencies are released.
  34. Resolving deprecation warnings
  35. ==============================
  36. Before upgrading, it's a good idea to resolve any deprecation warnings raised
  37. by your project while using your current version of Django. Fixing these
  38. warnings before upgrading ensures that you're informed about areas of the code
  39. that need altering.
  40. In Python, deprecation warnings are silenced by default. You must turn them on
  41. using the ``-Wall`` Python command line option or the :envvar:`PYTHONWARNINGS`
  42. environment variable. For example, to show warnings while running tests:
  43. .. code-block:: console
  44. $ python -Wall manage.py test
  45. If you're not using the Django test runner, you may need to also ensure that
  46. any console output is not captured which would hide deprecation warnings. For
  47. example, if you use `py.test`:
  48. .. code-block:: console
  49. $ PYTHONWARNINGS=all py.test tests --capture=no
  50. Resolve any deprecation warnings with your current version of Django before
  51. continuing the upgrade process.
  52. Third party applications might use deprecated APIs in order to support multiple
  53. versions of Django, so deprecation warnings in packages you've installed don't
  54. necessarily indicate a problem. If a package doesn't support the latest version
  55. of Django, consider raising an issue or sending a pull request for it.
  56. Installation
  57. ============
  58. Once you're ready, it is time to :doc:`install the new Django version
  59. </topics/install>`. If you are using virtualenv_ and it is a major upgrade, you
  60. might want to set up a new environment with all the dependencies first.
  61. Exactly which steps you will need to take depends on your installation process.
  62. The most convenient way is to use pip_ with the ``--upgrade`` or ``-U`` flag:
  63. .. code-block:: console
  64. $ pip install -U Django
  65. pip_ also automatically uninstalls the previous version of Django.
  66. If you use some other installation process, you might have to manually
  67. :ref:`uninstall the old Django version <removing-old-versions-of-django>` and
  68. should look at the complete installation instructions.
  69. .. _pip: https://pip.pypa.io/
  70. .. _virtualenv: http://www.virtualenv.org/
  71. Testing
  72. =======
  73. When the new environment is set up, :doc:`run the full test suite
  74. </topics/testing/overview>` for your application. Again, it's useful to turn
  75. on deprecation warnings on so they're shown in the test output (you can also
  76. use the flag if you test your app manually using ``manage.py runserver``):
  77. .. code-block:: console
  78. $ python -Wall manage.py test
  79. After you have run the tests, fix any failures. While you have the release
  80. notes fresh in your mind, it may also be a good time to take advantage of new
  81. features in Django by refactoring your code to eliminate any deprecation
  82. warnings.
  83. Deployment
  84. ==========
  85. When you are sufficiently confident your app works with the new version of
  86. Django, you're ready to go ahead and :doc:`deploy </howto/deployment/index>`
  87. your upgraded Django project.
  88. If you are using caching provided by Django, you should consider clearing your
  89. cache after upgrading. Otherwise you may run into problems, for example, if you
  90. are caching pickled objects as these objects are not guaranteed to be
  91. pickle-compatible across Django versions. A past instance of incompatibility
  92. was caching pickled :class:`~django.http.HttpResponse` objects, either
  93. directly or indirectly via the :func:`~django.views.decorators.cache.cache_page`
  94. decorator.