{"title":"How to upgrade Django to a newer version","version":"4.0","locale":"ja","docname":"howto/upgrade-version","url":"/ja/4.0/howto/upgrade-version/","canonical":"https://djangodocs.dev/ja/4.0/howto/upgrade-version/","summary":"時には更新作業は複雑な手順になってしまうことがありますが、Django の最新版に更新すると、以下ような恩恵が受けられます。 新しい機能や改善点が追加される。 バグが修正される。 Older version of Django will eventually no longer receive security…","html":"<h1>How to upgrade Django to a newer version<a class=\"heading-anchor\" href=\"#how-to-upgrade-django-to-a-newer-version\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>時には更新作業は複雑な手順になってしまうことがありますが、Django の最新版に更新すると、以下ような恩恵が受けられます。</p>\n<ul class=\"simple\">\n<li><p>新しい機能や改善点が追加される。</p></li>\n<li><p>バグが修正される。</p></li>\n<li><p>Older version of Django will eventually no longer receive security updates.\n(see <a class=\"reference internal\" href=\"/ja/4.0/internals/release-process/#supported-versions-policy\"><span class=\"std std-ref\">サポートバージョン</span></a>).</p></li>\n<li><p>Django が新しくリリースされた時に更新して、コードベースを最新の状態に保っておけば、将来の更新作業が楽になる。</p></li>\n</ul>\n<p>このセクションでは、更新作業ができるかぎりスムーズに行う助けになるよう、特に注意するべきことをいくつか説明しています。</p>\n<section id=\"required-reading\">\n<h2>更新時に読むべきドキュメント<a class=\"heading-anchor\" href=\"#required-reading\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>はじめて Django を更新する時には、<a class=\"reference internal\" href=\"/ja/4.0/internals/release-process/\"><span class=\"doc\">Django のリリースプロセスガイド</span></a> を読んでおくと役に立つでしょう。</p>\n<p>Afterward, you should familiarize yourself with the changes that were made in\nthe new Django version(s):</p>\n<ul class=\"simple\">\n<li><p>まず、<a class=\"reference internal\" href=\"/ja/4.0/releases/\"><span class=\"doc\">リリースノート</span></a> を読みましょう。読む必要があるのは、現在の Django のバージョンの1つ後から、更新しようと考えているターゲットのバージョンまでの、それぞれの「最後の (final) リリース」のリリースノートです。</p></li>\n<li><p>そして、対応するバージョンの  <a class=\"reference internal\" href=\"/ja/4.0/internals/deprecation/\"><span class=\"doc\">非推奨機能のタイムライン</span></a> にも目を通します。</p></li>\n</ul>\n<p>中でも特に、後方互換性のない変更点に注意してください。この点に注目すると、正しく更新するために必要なことがはっきりとわかるようになります。</p>\n<p>If you're upgrading through more than one feature version (e.g. 2.0 to 2.2),\nit's usually easier to upgrade through each feature release incrementally\n(2.0 to 2.1 to 2.2) rather than to make all the changes for each feature\nrelease at once. For each feature release, use the latest patch release (e.g.\nfor 2.1, use 2.1.15).</p>\n<p>あるLTSから次のLTSにアップグレードする場合は、インクリメンタルなアップグレードする方法を推奨します。</p>\n</section>\n<section id=\"dependencies\">\n<h2>依存関係<a class=\"heading-anchor\" href=\"#dependencies\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>ほとんどの場合、Django が依存しているパッケージも最新版に更新する必要があるでしょう。その Django のバージョンがリリースされたばかりで、依存関係にあるパッケージがきちんとメンテナンスされていなかった場合、新バージョンの Django に必要なパッケージがまだインストールできないかもしれません。そのような場合には、そうした Django の依存パッケージの新バージョンが使えるようになるまで、少し待たなければならない場合があります。</p>\n</section>\n<section id=\"resolving-deprecation-warnings\">\n<h2>廃止予定警告を解決する<a class=\"heading-anchor\" href=\"#resolving-deprecation-warnings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>アップグレードの前、Django の現在のバージョンを使っている間に、プロジェクトが挙げてくる廃止予定警告を解決しておくのがよいでしょう。アップグレードの前にこれらの警告を解決することで、コードが警告を必要とする領域について通知されるようにできます。</p>\n<p>In Python, deprecation warnings are silenced by default. You must turn them on\nusing the <code class=\"docutils literal notranslate\"><span class=\"pre\">-Wa</span></code> Python command line option or the <span class=\"target\" id=\"index-0\"></span><a class=\"reference external\" href=\"https://docs.python.org/3/using/cmdline.html#envvar-PYTHONWARNINGS\" title=\"(in Python v3.14)\"><code class=\"xref std std-envvar docutils literal notranslate\"><span class=\"pre\">PYTHONWARNINGS</span></code></a>\nenvironment variable. For example, to show warnings while running tests:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-0-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>python<span class=\"w\"> </span>-Wa<span class=\"w\"> </span>manage.py<span class=\"w\"> </span><span class=\"nb\">test</span>\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-0-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py -Wa manage.py test\n</code></pre></div></div></div>\n<p>If you're not using the Django test runner, you may need to also ensure that\nany console output is not captured which would hide deprecation warnings. For\nexample, if you use <a class=\"reference external\" href=\"https://docs.pytest.org/\">pytest</a>:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span><span class=\"nv\">PYTHONWARNINGS</span><span class=\"o\">=</span>always<span class=\"w\"> </span>pytest<span class=\"w\"> </span>tests<span class=\"w\"> </span>--capture<span class=\"o\">=</span>no\n</code></pre></div>\n<p>アップグレードプロセスを続ける前に、Django の現在のバージョンで廃止予定警告を解決してください。</p>\n<p>Django の複数バージョンをサポートするために、サードパーティアプリケーションは廃止される API を使用しているかもしれません。そのため、インストールしたパッケージの廃止予定警告は必ずしも問題を示しません。パッケージが Django の最新のバージョンをサポートしていない場合、問題を提起するかプルリクエストを送ることを考えてみてください。</p>\n</section>\n<section id=\"installation\">\n<h2>インストール<a class=\"heading-anchor\" href=\"#installation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Once you're ready, it is time to <a class=\"reference internal\" href=\"/ja/4.0/topics/install/\"><span class=\"doc\">install the new Django version</span></a>. If you are using a <a class=\"reference external\" href=\"https://docs.python.org/3/library/venv.html#module-venv\" title=\"(in Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">virtual</span> <span class=\"pre\">environment</span></code></a> and it\nis a major upgrade, you might want to set up a new environment with all the\ndependencies first.</p>\n<p>Django を <a class=\"reference external\" href=\"https://pip.pypa.io/\">pip</a> でインストールした場合は、<code class=\"docutils literal notranslate\"><span class=\"pre\">--upgrade</span></code> か <code class=\"docutils literal notranslate\"><span class=\"pre\">-U</span></code> フラグが使用できます。</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-1-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>python<span class=\"w\"> </span>-m<span class=\"w\"> </span>pip<span class=\"w\"> </span>install<span class=\"w\"> </span>-U<span class=\"w\"> </span>Django\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-1-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py -m pip install -U Django\n</code></pre></div></div></div>\n</section>\n<section id=\"testing\">\n<h2>テスト<a class=\"heading-anchor\" href=\"#testing\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>新しい環境が設定されたら、 <span class=\"xref std std-doc\">run the full test suite</span> 。テストの出力に表示されるように、廃止予定の警告を有効にすると便利です。 (<code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span> <span class=\"pre\">runserver</span></code> を使用してアプリケーションを手動でテストする場合は、フラグを使用することもできます)</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-2-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>python<span class=\"w\"> </span>-Wa<span class=\"w\"> </span>manage.py<span class=\"w\"> </span><span class=\"nb\">test</span>\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-2-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py -Wa manage.py test\n</code></pre></div></div></div>\n<p>テストを実行したら、テストに失敗した点をすべて修正しましょう。リリースノートの内容を心に留めながらコードをリファクタリングして、非推奨の警告が出ないようにすれば、Django の新しい機能の恩恵も受けられるかもしれません。</p>\n</section>\n<section id=\"deployment\">\n<h2>デプロイ<a class=\"heading-anchor\" href=\"#deployment\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>新しいバージョンの Django でもアプリケーションが動作すると自信を持って言えるようになったならば、更新した Django プロジェクトを <a class=\"reference internal\" href=\"/ja/4.0/howto/deployment/\"><span class=\"doc\">デプロイ</span></a> する準備ができたことになります．</p>\n<p>Django が提供するキャッシュを利用している場合には、更新後にキャッシュをクリアしなければなりません。クリアしなかった場合にはどんな問題が起こり得るでしょうか？ たとえば、pickle 化したオブジェクトをキャッシュしていた場合には、複数のバージョンの Django にわたって pickle の互換性が保証されません。過去の非互換性の例では、pickle 化された <a class=\"reference internal\" href=\"/ja/4.0/ref/request-response/#django.http.HttpResponse\" title=\"django.http.HttpResponse\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponse</span></code></a> オブジェクトを、 <a class=\"reference internal\" href=\"/ja/4.0/topics/cache/#django.views.decorators.cache.cache_page\" title=\"django.views.decorators.cache.cache_page\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">cache_page()</span></code></a> デコレータを介して直接的または間接的にキャッシュしていました。</p>\n</section>","rootId":"how-to-upgrade-django-to-a-newer-version","toc":[{"title":"更新時に読むべきドキュメント","anchor":"required-reading","children":[]},{"title":"依存関係","anchor":"dependencies","children":[]},{"title":"廃止予定警告を解決する","anchor":"resolving-deprecation-warnings","children":[]},{"title":"インストール","anchor":"installation","children":[]},{"title":"テスト","anchor":"testing","children":[]},{"title":"デプロイ","anchor":"deployment","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"「How-to」ガイド","url":"/ja/4.0/howto/"}],"prev":{"docname":"howto/deployment/checklist","title":"デプロイチェックリスト","url":"/ja/4.0/howto/deployment/checklist/"},"next":{"docname":"howto/error-reporting","title":"How to manage error reporting","url":"/ja/4.0/howto/error-reporting/"},"formats":{"html":"/ja/4.0/howto/upgrade-version/","markdown":"/ja/4.0/howto/upgrade-version.md","json":"/ja/4.0/howto/upgrade-version.json"},"source":"https://github.com/django/django/blob/stable/4.0.x/docs/howto/upgrade-version.txt","official":"https://docs.djangoproject.com/ja/4.0/howto/upgrade-version/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}