{"title":"Django の新しいバージョンへの更新","version":"2.0","locale":"ja","docname":"howto/upgrade-version","url":"/ja/2.0/howto/upgrade-version/","canonical":"https://djangodocs.dev/ja/2.0/howto/upgrade-version/","summary":"時には更新作業は複雑な手順になってしまうことがありますが、Django の最新版に更新すると、以下ような恩恵が受けられます。","html":"<h1>Django の新しいバージョンへの更新<a class=\"heading-anchor\" href=\"#upgrading-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/2.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/2.0/internals/release-process/\"><span class=\"doc\">Django のリリースプロセスガイド</span></a> を読んでおくと役に立つでしょう。</p>\n<p>更新を行う前には、新しいバージョンの Django ではどのような点が変更されたのかをよく知っておく必要があります。</p>\n<ul class=\"simple\">\n<li><p>まず、<a class=\"reference internal\" href=\"/ja/2.0/releases/\"><span class=\"doc\">リリースノート</span></a> を読みましょう。読む必要があるのは、現在の Django のバージョンの1つ後から、更新しようと考えているターゲットのバージョンまでの、それぞれの「最後の (final) リリース」のリリースノートです。</p></li>\n<li><p>そして、対応するバージョンの  <a class=\"reference internal\" href=\"/ja/2.0/internals/deprecation/\"><span class=\"doc\">非推奨機能のタイムライン</span></a> にも目を通します。</p></li>\n</ul>\n<p>中でも特に、後方互換性のない変更点に注意してください。この点に注目すると、正しく更新するために必要なことがはっきりとわかるようになります。</p>\n<p>たとえば A.B から A.B+2 のように複数の機能バージョンをアップグレードする場合は、各機能リリースのすべての変更を一度に行うのではなく、各機能リリースを A.B → A.B+1 → A.B+2 のように段階的にアップグレードする方が簡単です。 機能リリースごとに、最新のパッチリリース (A.B.C) を使用してください。</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>Python では、デフォルトでは廃止予定警告は無効化されています。<code class=\"docutils literal notranslate\">-Wall</code> Python コマンドラインオプションか <span class=\"target\" id=\"index-2\"></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\">PYTHONWARNINGS</code></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>python -Wall manage.py <span class=\"nb\">test</span>\n</code></pre></div>\n<p>Django のテスト実行環境を使用していない場合は、廃止予定警告を隠すような、コンソール出力がキャプチャされていないことを確認する必要があります。例えば、py.test を使っている場合:</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>all py.test tests --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>さあ、準備ができたら、<a class=\"reference internal\" href=\"/ja/2.0/topics/install/\"><span class=\"doc\">新しいバージョンの Django をインストールする</span></a> 時です。<a class=\"reference external\" href=\"https://virtualenv.pypa.io/\">virtualenv</a> を使っていて、これが Django のメジャーアップデートなら、<a class=\"reference external\" href=\"https://virtualenv.pypa.io/\">virtualenv</a> で新しい環境をセットアップして、そこに Django を依存パッケージとともにインストールしてもいいでしょう。</p>\n<p>次にどのステップを踏むべきかはあなたのインストールの進め方によって変わりますが、一番簡単な方法は、次のように <a class=\"reference external\" href=\"https://pip.pypa.io/\">pip</a> に <code class=\"docutils literal notranslate\">--upgrade</code> または -U フラグを付けて実行するというものです。</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>pip install -U Django\n</code></pre></div>\n<p><a class=\"reference external\" href=\"https://pip.pypa.io/\">pip</a> を使えば、過去のバージョンの Django も自動的にアンインストールしてくれます。</p>\n<p>これ以外のインストールの進め方を選んだ人は、手動で <a class=\"reference internal\" href=\"/ja/2.0/topics/install/#removing-old-versions-of-django\"><span class=\"std std-ref\">古いバージョンの Django をアンインストール</span></a> して、完全なインストール手順を読む必要があるかもしれません。</p>\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\">manage.py runserver</code> を使用してアプリケーションを手動でテストする場合は、フラグを使用することもできます)</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>python -Wall manage.py <span class=\"nb\">test</span>\n</code></pre></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/2.0/howto/deployment/\"><span class=\"doc\">デプロイ</span></a> する準備ができたことになります．</p>\n<p>Django が提供するキャッシュを利用している場合には、更新後にキャッシュをクリアしなければなりません。クリアしなかった場合にはどんな問題が起こり得るでしょうか？ たとえば、pickle 化したオブジェクトをキャッシュしていた場合には、複数のバージョンの Django にわたって pickle の互換性が保証されません。過去の非互換性の例では、pickle 化された <a class=\"reference internal\" href=\"/ja/2.0/ref/request-response/#django.http.HttpResponse\" title=\"django.http.HttpResponse\"><code class=\"xref py py-class docutils literal notranslate\">HttpResponse</code></a> オブジェクトを、 <a class=\"reference internal\" href=\"/ja/2.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\">cache_page()</code></a> デコレータを介して直接的または間接的にキャッシュしていました。</p>\n</section>","rootId":"upgrading-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/2.0/howto/"}],"prev":{"docname":"howto/deployment/checklist","title":"デプロイチェックリスト","url":"/ja/2.0/howto/deployment/checklist/"},"next":{"docname":"howto/error-reporting","title":"Error reporting","url":"/ja/2.0/howto/error-reporting/"},"formats":{"html":"/ja/2.0/howto/upgrade-version/","markdown":"/ja/2.0/howto/upgrade-version.md","json":"/ja/2.0/howto/upgrade-version.json"},"source":"https://github.com/django/django/blob/stable/2.0.x/docs/howto/upgrade-version.txt","official":"https://docs.djangoproject.com/ja/2.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","pt-br","ko","es","el","pl"]}