{"title":"Django の新しいバージョンへの更新","version":"1.10","locale":"ja","docname":"howto/upgrade-version","url":"/ja/1.10/howto/upgrade-version/","canonical":"https://djangodocs.dev/ja/1.10/howto/upgrade-version/","summary":"時には更新作業は複雑な手順になってしまうことがありますが、Django の最新版に更新すると、以下ような恩恵が受けられます。 新しい機能や改善点が追加される。 バグが修正される。 古いバージョンの Django は最終的にはセキュリティアップデートが受けられなくなる ( サポートバージョン を参照してください)。 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>古いバージョンの Django は最終的にはセキュリティアップデートが受けられなくなる (<a class=\"reference internal\" href=\"/ja/1.10/internals/release-process/#backwards-compatibility-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/1.10/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/1.10/releases/\"><span class=\"doc\">リリースノート</span></a> を読みましょう。読む必要があるのは、現在の Django のバージョンの1つ後から、更新しようと考えているターゲットのバージョンまでの、それぞれの「最後の (final) リリース」のリリースノートです。</p></li>\n<li><p>そして、対応するバージョンの  <a class=\"reference internal\" href=\"/ja/1.10/internals/deprecation/\"><span class=\"doc\">非推奨機能のタイムライン</span></a> にも目を通します。</p></li>\n</ul>\n<p>中でも特に、後方互換性のない変更点に注意してください。この点に注目すると、正しく更新するために必要なことがはっきりとわかるようになります。</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>Resolving deprecation warnings<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>Before upgrading, it's a good idea to resolve any deprecation warnings raised\nby your project while using your current version of Django. Fixing these\nwarnings before upgrading ensures that you're informed about areas of the code\nthat need altering.</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\">-Wall</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=\"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>-Wall<span class=\"w\"> </span>manage.py<span class=\"w\"> </span><span class=\"nb\">test</span>\n</code></pre></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 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<span class=\"w\"> </span>py.test<span class=\"w\"> </span>tests<span class=\"w\"> </span>--capture<span class=\"o\">=</span>no\n</code></pre></div>\n<p>Resolve any deprecation warnings with your current version of Django before\ncontinuing the upgrade process.</p>\n<p>Third party applications might use deprecated APIs in order to support multiple\nversions of Django, so deprecation warnings in packages you've installed don't\nnecessarily indicate a problem. If a package doesn't support the latest version\nof Django, consider raising an issue or sending a pull request for it.</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/1.10/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\"><span class=\"pre\">--upgrade</span></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<span class=\"w\"> </span>install<span class=\"w\"> </span>-U<span class=\"w\"> </span>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/1.10/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>When the new environment is set up, <a class=\"reference internal\" href=\"/ja/1.10/topics/testing/overview/\"><span class=\"doc\">run the full test suite</span></a> for your application. Again, it's useful to turn\non deprecation warnings on so they're shown in the test output (you can also\nuse the flag if you test your app manually using <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span> <span class=\"pre\">runserver</span></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<span class=\"w\"> </span>-Wall<span class=\"w\"> </span>manage.py<span class=\"w\"> </span><span class=\"nb\">test</span>\n</code></pre></div>\n<p>テストを実行したら、テストに失敗した点をすべて修正しましょう。リリースノートの内容を心に留めながらコードをリファクタリングして、非推奨の警告が出ないようにすれば、Django の新しい機能の恩恵も受けられるかもしれません。</p>\n</section>\n<section id=\"deployment\">\n<h2>Deployment<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/1.10/howto/deployment/\"><span class=\"doc\">デプロイ</span></a> する準備ができたことになります．</p>\n<p>Django が提供するキャッシュを利用している場合には、更新後にキャッシュをクリアしなければなりません。クリアしなかった場合にはどんな問題が起こり得るでしょうか？ たとえば、pickle 化したオブジェクトをキャッシュしていた場合には、複数のバージョンの Django にわたって pickle の互換性が保証されません。A past instance of incompatibility was caching pickled <a class=\"reference internal\" href=\"/ja/1.10/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> objects, either directly or indirectly via the <a class=\"reference internal\" href=\"/ja/1.10/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> decorator.</p>\n</section>","rootId":"upgrading-django-to-a-newer-version","toc":[{"title":"更新時に読むべきドキュメント","anchor":"required-reading","children":[]},{"title":"依存関係","anchor":"dependencies","children":[]},{"title":"Resolving deprecation warnings","anchor":"resolving-deprecation-warnings","children":[]},{"title":"インストール","anchor":"installation","children":[]},{"title":"テスト","anchor":"testing","children":[]},{"title":"Deployment","anchor":"deployment","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"「How-to」ガイド","url":"/ja/1.10/howto/"}],"prev":{"docname":"howto/deployment/checklist","title":"Deployment checklist","url":"/ja/1.10/howto/deployment/checklist/"},"next":{"docname":"howto/error-reporting","title":"Error reporting","url":"/ja/1.10/howto/error-reporting/"},"formats":{"html":"/ja/1.10/howto/upgrade-version/","markdown":"/ja/1.10/howto/upgrade-version.md","json":"/ja/1.10/howto/upgrade-version.json"},"source":"https://github.com/django/django/blob/stable/1.10.x/docs/howto/upgrade-version.txt","official":"https://docs.djangoproject.com/ja/1.10/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","fr","ja","id","pt-br","es","el","pl"]}