---
title: "Django 2.0 リリースノート"
version: 6.0
locale: ja
source: https://docs.djangoproject.com/ja/6.0/releases/2.0/
canonical: https://djangodocs.dev/ja/6.0/releases/2.0/
---
# Django 2.0 リリースノート

*December 2, 2017*

Django 2.0 へようこそ！

このリリースノートでは、 [バージョン 2.0 の新機能](#whats-new-2-0) と、Django 1.11 以前からアップグレードする際に注意すべき、 [後方互換性のない変更](#backwards-incompatible-2-0) について説明します。 [非推奨サイクルが終了した機能を廃止しました](#removed-features-2-0) 。また、 [一部の機能を非推奨](#deprecated-features-2-0) としました。

このリリースから Django は [loose form of semantic versioning](/ja/6.0/internals/release-process/#internal-release-cadence) を使用し始めますが、通常 2.0 リリースで期待されるような後方互換性を損なう大きな変更はありません。アップグレードは、これまでのフィーチャーリリースと同等の労力で行えるはずです。

既存のプロジェクトをアップデートするときは、 [Django の新しいバージョンへの更新](/ja/6.0/howto/upgrade-version/) ガイドに従ってください。

## Python バージョン間の互換性

Django 2.0 は Python 3.4, 3.5, 3.6, 3.7 をサポートします。各バージョン系列の最新リリースのみを公式にサポートし、最新リリースを使用することを **強く推奨** します。

Python 2.7 をサポートするのは、Django 1.11.x シリーズで最後になります。

Django 2.0 は Python 3.4 をサポートする最後のリリース系列になる予定です。Django 2.0 (April 2019) の end-of-life 後もまだ Python 3.4 を使用する予定であれば、代わりに Django 1.11 LTS (2020年4月までサポート) にとどまってください。ただし、2019年3月には Python 3.4 自体が end-of-life を迎えることに注意してください。

## 古いバージョンの Django をサポートするサードパーティのライブラリ

Django 2.0 リリース後は、サードパーティアプリの開発者は 1.11 より前のバージョンの Django のサポートを終えるよう推奨します。このとき、`python -Wd` を使ったパッケージテストを実行して、廃止予定 (deprecation) の警告を出力できます。廃止予定の警告が出ないように修正すれば、アプリケーションは Django 2.0 と互換性のある状態になっているはずです。

## Django 2.0 の新機能

### URL ルーティングの構文の簡略化

The new [`django.urls.path()`](/ja/6.0/ref/urls/#django.urls.path) function allows a simpler, more readable URL
routing syntax. For example, this example from previous Django releases:

```
url(r"^articles/(?P<year>[0-9]{4})/$", views.year_archive),
```

次のように書き換えられます。

```
path("articles/<int:year>/", views.year_archive),
```

新しい構文では、URL パラメータの型強制がサポートされます。この例では、ビューが受け取る `year` キーワード引数は、文字列ではなく整数になります。また、書き換えた例でマッチする URL の制約も少し緩和されています。たとえば、year として 10000 を指定したとしてもマッチします。正規表現の例にあるような、数字が4文字ちょうどでなければならないという制約がないからです。

`django.conf.urls.url()` 関数は [`django.urls.re_path()`](/ja/6.0/ref/urls/#django.urls.re_path) から利用できるようになりました。差し迫った廃止は必要ないため、後方互換性のために、関数は古い場所にも残されます。また `django.conf.urls.include()` 関数も `django.urls` からインポートできるようになりました。したがって、URLconf の中では `from django.urls import include, path, re_path` とインポートができます。

新しい構文と詳細な解説を紹介するために、[URL ディスパッチャ](/ja/6.0/topics/http/urls/) ドキュメントをアップデートしています。

### モバイルフレンドリーな `contrib.admin`

admin サイトがレスポンシブになり、主要な全モバイルデバイスをサポートするようになりました。古いブラウザーでは、多少のデグレーションが発生する可能性があります。

### Windows 式

新しい [`Window`](/ja/6.0/ref/models/expressions/#django.db.models.expressions.Window) 式を使うと、クエリセットに `OVER` 句を追加できるようになります。式の中では、[window 関数](/ja/6.0/ref/models/database-functions/#window-functions) と [aggregate 関数](/ja/6.0/ref/models/querysets/#aggregation-functions) が使用できます。

### マイナーな機能

#### [`django.contrib.admin`](/ja/6.0/ref/contrib/admin/#module-django.contrib.admin)

- The new [`ModelAdmin.autocomplete_fields`](/ja/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields) attribute and
  [`ModelAdmin.get_autocomplete_fields()`](/ja/6.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_autocomplete_fields) method allow using a
  [Select2](https://select2.org/) search widget for `ForeignKey` and
  `ManyToManyField`.

#### [`django.contrib.auth`](/ja/6.0/topics/auth/#module-django.contrib.auth)

- PBKDF2 パスワードハッシュに対するデフォルトのイテレーション回数が 36,000 から 100,000 に増加しました。

#### [`django.contrib.gis`](/ja/6.0/ref/contrib/gis/#module-django.contrib.gis)

- Added MySQL support for the
  [`AsGeoJSON`](/ja/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.AsGeoJSON) function,
  [`GeoHash`](/ja/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.GeoHash) function,
  [`IsValid`](/ja/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.IsValid) function,
  [`isvalid`](/ja/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-isvalid) lookup, and [distance lookups](/ja/6.0/ref/contrib/gis/geoquerysets/#distance-lookups).
- Added the [`Azimuth`](/ja/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Azimuth) and
  [`LineLocatePoint`](/ja/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.LineLocatePoint) functions,
  supported on PostGIS and SpatiaLite.
- Any [`GEOSGeometry`](/ja/6.0/ref/contrib/gis/geos/#django.contrib.gis.geos.GEOSGeometry) imported from GeoJSON now
  has its SRID set.
- Added the [`OSMWidget.default_zoom`](/ja/6.0/ref/contrib/gis/forms-api/#django.contrib.gis.forms.widgets.OSMWidget.default_zoom) attribute to customize the map's
  default zoom level.
- Made metadata readable and editable on rasters through the
  [`metadata`](/ja/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster.metadata),
  [`info`](/ja/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster.info), and
  [`metadata`](/ja/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALBand.metadata) attributes.
- Allowed passing driver-specific creation options to
  [`GDALRaster`](/ja/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster) objects using `papsz_options`.
- Allowed creating [`GDALRaster`](/ja/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster) objects in
  GDAL's internal virtual filesystem. Rasters can now be [created from and
  converted to binary data](/ja/6.0/ref/contrib/gis/gdal/#gdal-raster-vsimem) in-memory.
- The new [`GDALBand.color_interp()`](/ja/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALBand.color_interp) method returns the color
  interpretation for the band.

#### [`django.contrib.postgres`](/ja/6.0/ref/contrib/postgres/#module-django.contrib.postgres)

- The new `distinct` argument for
  [`ArrayAgg`](/ja/6.0/ref/contrib/postgres/aggregates/#django.contrib.postgres.aggregates.ArrayAgg) determines if
  concatenated values will be distinct.
- The new [`RandomUUID`](/ja/6.0/ref/contrib/postgres/functions/#django.contrib.postgres.functions.RandomUUID) database
  function returns a version 4 UUID. It requires use of PostgreSQL's
  `pgcrypto` extension which can be activated using the new
  [`CryptoExtension`](/ja/6.0/ref/contrib/postgres/operations/#django.contrib.postgres.operations.CryptoExtension) migration
  operation.
- [`django.contrib.postgres.indexes.GinIndex`](/ja/6.0/ref/contrib/postgres/indexes/#django.contrib.postgres.indexes.GinIndex) now supports the
  `fastupdate` and `gin_pending_list_limit` parameters.
- The new [`GistIndex`](/ja/6.0/ref/contrib/postgres/indexes/#django.contrib.postgres.indexes.GistIndex) class allows
  creating `GiST` indexes in the database. The new
  [`BtreeGistExtension`](/ja/6.0/ref/contrib/postgres/operations/#django.contrib.postgres.operations.BtreeGistExtension) migration
  operation installs the `btree_gist` extension to add support for operator
  classes that aren't built-in.
- [`inspectdb`](/ja/6.0/ref/django-admin/#django-admin-inspectdb) can now introspect `JSONField` and various
  `RangeField`s (`django.contrib.postgres` must be in `INSTALLED_APPS`).

#### [`django.contrib.sitemaps`](/ja/6.0/ref/contrib/sitemaps/#module-django.contrib.sitemaps)

- Added the `protocol` keyword argument to the
  [`GenericSitemap`](/ja/6.0/ref/contrib/sitemaps/#django.contrib.sitemaps.GenericSitemap) constructor.

#### キャッシュ

- `cache.set_many()` now returns a list of keys that failed to be inserted.
  For the built-in backends, failed inserts can only happen on memcached.

#### ファイルストレージ

- [`File.open()`](/ja/6.0/ref/files/file/#django.core.files.File.open) can be used as a context
  manager, e.g. `with file.open() as f:`.

#### フォーム

- The new `date_attrs` and `time_attrs` arguments for
  [`SplitDateTimeWidget`](/ja/6.0/ref/forms/widgets/#django.forms.SplitDateTimeWidget) and
  [`SplitHiddenDateTimeWidget`](/ja/6.0/ref/forms/widgets/#django.forms.SplitHiddenDateTimeWidget) allow specifying different
  HTML attributes for the `DateInput` and `TimeInput` (or hidden)
  subwidgets.
- The new [`Form.errors.get_json_data()`](/ja/6.0/ref/forms/api/#django.forms.Form.errors.get_json_data) method returns form errors as
  a dictionary suitable for including in a JSON response.

#### ジェネリックビュー (汎用ビュー)

- The new [`ContextMixin.extra_context`](/ja/6.0/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.extra_context) attribute allows adding context
  in `View.as_view()`.

#### 管理コマンド

- [`inspectdb`](/ja/6.0/ref/django-admin/#django-admin-inspectdb) now translates MySQL's unsigned integer columns to
  `PositiveIntegerField` or `PositiveSmallIntegerField`.
- The new [`makemessages --add-location`](/ja/6.0/ref/django-admin/#cmdoption-makemessages-add-location) option controls the comment
  format in `.po` files.
- [`loaddata`](/ja/6.0/ref/django-admin/#django-admin-loaddata) can now [read from stdin](/ja/6.0/ref/django-admin/#loading-fixtures-stdin).
- The new [`diffsettings --output`](/ja/6.0/ref/django-admin/#cmdoption-diffsettings-output) option allows formatting the output
  in a unified diff format.
- On Oracle, [`inspectdb`](/ja/6.0/ref/django-admin/#django-admin-inspectdb) can now introspect `AutoField` if the
  column is created as an identity column.
- On MySQL, [`dbshell`](/ja/6.0/ref/django-admin/#django-admin-dbshell) now supports client-side TLS certificates.

#### マイグレーション

- The new [`squashmigrations --squashed-name`](/ja/6.0/ref/django-admin/#cmdoption-squashmigrations-squashed-name) option allows naming the
  squashed migration.

#### モデル

- The new [`StrIndex`](/ja/6.0/ref/models/database-functions/#django.db.models.functions.StrIndex) database function
  finds the starting index of a string inside another string.
- On Oracle, `AutoField` and `BigAutoField` are now created as [identity
  columns](https://docs.oracle.com/en/database/oracle/oracle-database/21/drdaa/intro-to-tools-and-products-supporting-migraiton.html#GUID-14E4817B-F3BC-4D99-B471-A0ACDC303CC9).
- The new `chunk_size` parameter of [`QuerySet.iterator()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.iterator) controls the
  number of rows fetched by the Python database client when streaming results
  from the database. For databases that don't support server-side cursors, it
  controls the number of results Django fetches from the database adapter.
- [`QuerySet.earliest()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.earliest), [`QuerySet.latest()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.latest), and
  [`Meta.get_latest_by`](/ja/6.0/ref/models/options/#django.db.models.Options.get_latest_by) now
  allow ordering by several fields.
- Added the [`ExtractQuarter`](/ja/6.0/ref/models/database-functions/#django.db.models.functions.ExtractQuarter) function to
  extract the quarter from [`DateField`](/ja/6.0/ref/models/fields/#django.db.models.DateField) and
  [`DateTimeField`](/ja/6.0/ref/models/fields/#django.db.models.DateTimeField), and exposed it through the
  [`quarter`](/ja/6.0/ref/models/querysets/#std-fieldlookup-quarter) lookup.
- Added the [`TruncQuarter`](/ja/6.0/ref/models/database-functions/#django.db.models.functions.TruncQuarter) function to
  truncate [`DateField`](/ja/6.0/ref/models/fields/#django.db.models.DateField) and
  [`DateTimeField`](/ja/6.0/ref/models/fields/#django.db.models.DateTimeField) to the first day of a quarter.
- Added the [`db_tablespace`](/ja/6.0/ref/models/indexes/#django.db.models.Index.db_tablespace) parameter to
  class-based indexes.
- If the database supports a native duration field (Oracle and PostgreSQL),
  [`Extract`](/ja/6.0/ref/models/database-functions/#django.db.models.functions.Extract) now works with
  [`DurationField`](/ja/6.0/ref/models/fields/#django.db.models.DurationField).
- Added the `of` argument to [`QuerySet.select_for_update()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.select_for_update), supported
  on PostgreSQL and Oracle, to lock only rows from specific tables rather than
  all selected tables. It may be helpful particularly when
  [`select_for_update()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.select_for_update) is used in conjunction with
  [`select_related()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.select_related).
- The new `field_name` parameter of [`QuerySet.in_bulk()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.in_bulk) allows fetching
  results based on any unique model field.
- [`CursorWrapper.callproc()`](/ja/6.0/topics/db/sql/#django.db.models.CursorWrapper.callproc) now takes an optional dictionary of keyword
  parameters, if the backend supports this feature. Of Django's built-in
  backends, only Oracle supports it.
- The new [`connection.execute_wrapper()`](/ja/6.0/topics/db/instrumentation/#django.db.backends.base.DatabaseWrapper.execute_wrapper) method allows
  [installing wrappers around execution of database queries](/ja/6.0/topics/db/instrumentation/).
- The new `filter` argument for built-in aggregates allows [adding
  different conditionals](/ja/6.0/ref/models/conditional-expressions/#conditional-aggregation) to multiple aggregations
  over the same fields or relations.
- Added support for expressions in [`Meta.ordering`](/ja/6.0/ref/models/options/#django.db.models.Options.ordering).
- The new `named` parameter of [`QuerySet.values_list()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.values_list) allows fetching
  results as named tuples.
- The new [`FilteredRelation`](/ja/6.0/ref/models/querysets/#django.db.models.FilteredRelation) class allows adding an `ON` clause to
  querysets.

#### ページネーション

- Added [`Paginator.get_page()`](/ja/6.0/ref/paginator/#django.core.paginator.Paginator.get_page)
  to provide the documented pattern of handling invalid page numbers.

#### Request と Response

- The [`runserver`](/ja/6.0/ref/django-admin/#django-admin-runserver) web server supports HTTP 1.1.

#### テンプレート

- To increase the usefulness of [`Engine.get_default()`](/ja/6.0/ref/templates/api/#django.template.Engine.get_default) in third-party
  apps, it now returns the first engine if multiple `DjangoTemplates` engines
  are configured in `TEMPLATES` rather than raising `ImproperlyConfigured`.
- カスタムのテンプレートタグはキーワード引数のみを受け取ることができるようになりました。

#### テスト

- [`LiveServerTestCase`](/ja/6.0/topics/testing/tools/#django.test.LiveServerTestCase) にスレッドのサポートが追加されました。
- Oracle のテストテーブルスペースパラメータをカスタマイズするための新しい設定項目として、[`DATAFILE_SIZE`](/ja/6.0/ref/settings/#std-setting-DATAFILE_SIZE)、[`DATAFILE_TMP_SIZE`](/ja/6.0/ref/settings/#std-setting-DATAFILE_TMP_SIZE)、[`DATAFILE_EXTSIZE`](/ja/6.0/ref/settings/#std-setting-DATAFILE_EXTSIZE)、[`DATAFILE_TMP_EXTSIZE`](/ja/6.0/ref/settings/#std-setting-DATAFILE_TMP_EXTSIZE) が追加されました。

#### バリデータ

- The new [`ProhibitNullCharactersValidator`](/ja/6.0/ref/validators/#django.core.validators.ProhibitNullCharactersValidator) disallows the null
  character in the input of the [`CharField`](/ja/6.0/ref/forms/fields/#django.forms.CharField) form field
  and its subclasses. Null character input was observed from vulnerability
  scanning tools. Most databases silently discard null characters, but
  psycopg2 2.7+ raises an exception when trying to save a null character to
  a char/text field with PostgreSQL.

## 2.0 における後方互換性のない変更

### いくつかの場所におけバイト文字列のサポートの削除

To support native Python 2 strings, older Django versions had to accept both
bytestrings and Unicode strings. Now that Python 2 support is dropped,
bytestrings should only be encountered around input/output boundaries (handling
of binary fields or HTTP streams, for example). You might have to update your
code to limit bytestring usage to a minimum, as Django no longer accepts
bytestrings in certain code paths. Python's [`-b`](https://docs.python.org/3/using/cmdline.html#cmdoption-b) option may help detect
that mistake in your code.

For example, `reverse()` now uses `str()` instead of `force_text()` to
coerce the `args` and `kwargs` it receives, prior to their placement in
the URL. For bytestrings, this creates a string with an undesired `b` prefix
as well as additional quotes (`str(b'foo')` is `"b'foo'"`). To adapt, call
`decode()` on the bytestring before passing it to `reverse()`.

### データベースバックエンド API

このセクションでは、サードパーティのデータベースバックエンドで必要になる可能性のある変更について説明します。

- The `DatabaseOperations.datetime_cast_date_sql()`,
  `datetime_cast_time_sql()`, `datetime_trunc_sql()`,
  `datetime_extract_sql()`, and `date_interval_sql()` methods now return
  only the SQL to perform the operation instead of SQL and a list of
  parameters.
- Third-party database backends should add a `DatabaseWrapper.display_name`
  attribute with the name of the database that your backend works with. Django
  may use it in various messages, such as in system checks.
- The first argument of `SchemaEditor._alter_column_type_sql()` is now
  `model` rather than `table`.
- The first argument of `SchemaEditor._create_index_name()` is now
  `table_name` rather than `model`.
- To enable `FOR UPDATE OF` support, set
  `DatabaseFeatures.has_select_for_update_of = True`. If the database
  requires that the arguments to `OF` be columns rather than tables, set
  `DatabaseFeatures.select_for_update_of_column = True`.
- To enable support for [`Window`](/ja/6.0/ref/models/expressions/#django.db.models.expressions.Window)
  expressions, set `DatabaseFeatures.supports_over_clause` to `True`. You
  may need to customize the
  `DatabaseOperations.window_start_rows_start_end()` and/or
  `window_start_range_start_end()` methods.
- Third-party database backends should add a
  `DatabaseOperations.cast_char_field_without_max_length` attribute with the
  database data type that will be used in the
  [`Cast`](/ja/6.0/ref/models/database-functions/#django.db.models.functions.Cast) function for a `CharField` if the
  `max_length` argument isn't provided.
- The first argument of `DatabaseCreation._clone_test_db()` and
  `get_test_db_clone_settings()` is now `suffix` rather
  than `number` (in case you want to rename the signatures in your backend
  for consistency). `django.test` also now passes those values as strings
  rather than as integers.
- Third-party database backends should add a
  `DatabaseIntrospection.get_sequences()` method based on the stub in
  `BaseDatabaseIntrospection`.

### Oracle 11.2 に対するサポートの終了

The end of upstream support for Oracle 11.2 is Dec. 2020. Django 1.11 will be
supported until April 2020 which almost reaches this date. Django 2.0
officially supports Oracle 12.1+.

### デフォルトの MySQL の isolation レベルを read committed に変更

MySQL のデフォルトの isolation レベルは repeatable read ですが、この設定は Django の典型的な使用例でデータロスを引き起こす可能性があります。データロスを防ぎ、他のデータベースとの一貫性を保つため、デフォルトの isolation level が read committed に変更されました。必要があれば、[`DATABASES`](/ja/6.0/ref/settings/#std-setting-DATABASES) 設定を変更することで、[異なる isolation level を使う](/ja/6.0/ref/databases/#mysql-isolation-level) こともできます。

### [`AbstractUser.last_name`](/ja/6.0/ref/contrib/auth/#django.contrib.auth.models.User.last_name) の `max_length` が 150 文字に拡大

[`django.contrib.auth.models.User.last_name`](/ja/6.0/ref/contrib/auth/#django.contrib.auth.models.User.last_name) に対するマイグレーションが含まれます。`AbstractUser` を継承したカスタムのユーザーモデルがある場合、そのユーザーモデルに対するデータベースのマイグレーションを生成して適用する必要があります。

last name に 30 文字の制限を課し続けたい場合は、次のようなカスタムフォームを使用してください。

```
from django.contrib.auth.forms import UserChangeForm

class MyUserChangeForm(UserChangeForm):
    last_name = forms.CharField(max_length=30, required=False)
```

管理サイトでユーザーを編集する時にもこの制約を課し続けたい場合は、以下のように、フォームに `UserAdmin.form` を設定してください。

```
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

class MyUserAdmin(UserAdmin):
    form = MyUserChangeForm

admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)
```

### スライス後の `QuerySet.reverse()` および `last()` の禁止

Calling `QuerySet.reverse()` or `last()` on a sliced queryset leads to
unexpected results due to the slice being applied after reordering. This is
now prohibited, e.g.:

```pycon
>>> Model.objects.all()[:2].reverse()
Traceback (most recent call last):
...
TypeError: Cannot reverse a query once a slice has been taken.
```

### フォームフィールドに省略可能な引数を渡す時、位置引数として指定することができなくなりました。

To help prevent runtime errors due to incorrect ordering of form field
arguments, optional arguments of built-in form fields are no longer accepted
as positional arguments. For example:

```
forms.IntegerField(25, 10)
```

raises an exception and should be replaced with:

```
forms.IntegerField(max_value=25, min_value=10)
```

### `call_command()` validates the options it receives

`call_command()` now validates that the argument parser of the command being
called defines all of the options passed to `call_command()`.

For custom management commands that use options not created using
`parser.add_argument()`, add a `stealth_options` attribute on the command:

```
class MyCommand(BaseCommand):
    stealth_options = ("option_name", ...)
```

### Indexes no longer accept positional arguments

例:

```
models.Index(["headline", "-pub_date"], "index_name")
```

raises an exception and should be replaced with:

```
models.Index(fields=["headline", "-pub_date"], name="index_name")
```

### Foreign key constraints are now enabled on SQLite

This will appear as a backwards-incompatible change (`IntegrityError:
FOREIGN KEY constraint failed`) if attempting to save an existing model
instance that's violating a foreign key constraint.

Foreign keys are now created with `DEFERRABLE INITIALLY DEFERRED` instead of
`DEFERRABLE IMMEDIATE`. Thus, tables may need to be rebuilt to recreate
foreign keys with the new definition, particularly if you're using a pattern
like this:

```
from django.db import transaction

with transaction.atomic():
    Book.objects.create(author_id=1)
    Author.objects.create(id=1)
```

If you don't recreate the foreign key as `DEFERRED`, the first `create()`
would fail now that foreign key constraints are enforced.

Backup your database first! After upgrading to Django 2.0, you can then
rebuild tables using a script similar to this:

```
from django.apps import apps
from django.db import connection

for app in apps.get_app_configs():
    for model in app.get_models(include_auto_created=True):
        if model._meta.managed and not (model._meta.proxy or model._meta.swapped):
            for base in model.__bases__:
                if hasattr(base, "_meta"):
                    base._meta.local_many_to_many = []
            model._meta.local_many_to_many = []
            with connection.schema_editor() as editor:
                editor._remake_table(model)
```

This script hasn't received extensive testing and needs adaption for various
cases such as multiple databases. Feel free to contribute improvements.

In addition, because of a table alteration limitation of SQLite, it's
prohibited to perform [`RenameModel`](/ja/6.0/ref/migration-operations/#django.db.migrations.operations.RenameModel) and
[`RenameField`](/ja/6.0/ref/migration-operations/#django.db.migrations.operations.RenameField) operations on models or
fields referenced by other models in a transaction. In order to allow
migrations containing these operations to be applied, you must set the
`Migration.atomic` attribute to `False`.

### その他

- The `SessionAuthenticationMiddleware` class is removed. It provided no
  functionality since session authentication is unconditionally enabled in
  Django 1.10.
- The default HTTP error handlers (`handler404`, etc.) are now callables
  instead of dotted Python path strings. Django favors callable references
  since they provide better performance and debugging experience.
- [`RedirectView`](/ja/6.0/ref/class-based-views/base/#django.views.generic.base.RedirectView) no longer silences
  `NoReverseMatch` if the `pattern_name` doesn't exist.
- When `USE_L10N` is off, [`FloatField`](/ja/6.0/ref/forms/fields/#django.forms.FloatField) and
  [`DecimalField`](/ja/6.0/ref/forms/fields/#django.forms.DecimalField) now respect [`DECIMAL_SEPARATOR`](/ja/6.0/ref/settings/#std-setting-DECIMAL_SEPARATOR)
  and [`THOUSAND_SEPARATOR`](/ja/6.0/ref/settings/#std-setting-THOUSAND_SEPARATOR) during validation. For example, with the
  settings:

  ```
  USE_L10N = False
  USE_THOUSAND_SEPARATOR = True
  DECIMAL_SEPARATOR = ","
  THOUSAND_SEPARATOR = "."
  ```

  an input of `"1.345"` is now converted to `1345` instead of `1.345`.
- Subclasses of [`AbstractBaseUser`](/ja/6.0/topics/auth/customizing/#django.contrib.auth.models.AbstractBaseUser) are no
  longer required to implement `get_short_name()` and `get_full_name()`.
  (The base implementations that raise `NotImplementedError` are removed.)
  `django.contrib.admin` uses these methods if implemented but doesn't
  require them. Third-party apps that use these methods may want to adopt a
  similar approach.
- The `FIRST_DAY_OF_WEEK` and `NUMBER_GROUPING` format settings are now
  kept as integers in JavaScript and JSON i18n view outputs.
- [`assertNumQueries()`](/ja/6.0/topics/testing/tools/#django.test.TransactionTestCase.assertNumQueries) now ignores
  connection configuration queries. Previously, if a test opened a new database
  connection, those queries could be included as part of the
  `assertNumQueries()` count.
- The default size of the Oracle test tablespace is increased from 20M to 50M
  and the default autoextend size is increased from 10M to 25M.
- To improve performance when streaming large result sets from the database,
  [`QuerySet.iterator()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.iterator) now fetches 2000 rows at a time instead of 100.
  The old behavior can be restored using the `chunk_size` parameter. For
  example:

  ```
  Book.objects.iterator(chunk_size=100)
  ```
- Providing unknown package names in the `packages` argument of the
  [`JavaScriptCatalog`](/ja/6.0/topics/i18n/translation/#django.views.i18n.JavaScriptCatalog) view now raises `ValueError`
  instead of passing silently.
- A model instance's primary key now appears in the default `Model.__str__()`
  method, e.g. `Question object (1)`.
- `makemigrations` now detects changes to the model field `limit_choices_to`
  option. Add this to your existing migrations or accept an auto-generated
  migration for fields that use it.
- Performing queries that require [automatic spatial transformations](/ja/6.0/ref/contrib/gis/tutorial/#automatic-spatial-transformations) now raises `NotImplementedError`
  on MySQL instead of silently using non-transformed geometries.
- `django.core.exceptions.DjangoRuntimeWarning` is removed. It was only used
  in the cache backend as an intermediate class in `CacheKeyWarning`'s
  inheritance of `RuntimeWarning`.
- Renamed `BaseExpression._output_field` to `output_field`. You may need
  to update custom expressions.
- In older versions, forms and formsets combine their `Media` with widget
  `Media` by concatenating the two. The combining now tries to [preserve
  the relative order of elements in each list](/ja/6.0/topics/forms/media/#form-media-asset-order).
  `MediaOrderConflictWarning` is issued if the order can't be preserved.
- `django.contrib.gis.gdal.OGRException` is removed. It's been an alias for
  `GDALException` since Django 1.8.
- Support for GEOS 3.3.x is dropped.
- The way data is selected for `GeometryField` is changed to improve
  performance, and in raw SQL queries, those fields must now be wrapped in
  `connection.ops.select`. See the [Raw queries note](/ja/6.0/ref/contrib/gis/tutorial/#gis-raw-sql) in
  the GIS tutorial for an example.

## Features deprecated in 2.0

### `context` argument of `Field.from_db_value()` and `Expression.convert_value()`

The `context` argument of `Field.from_db_value()` and
`Expression.convert_value()` is unused as it's always an empty dictionary.
The signature of both methods is now:

```
(self, value, expression, connection)
```

代わりに、次のようにします:

```
(self, value, expression, connection, context)
```

Support for the old signature in custom fields and expressions remains until
Django 3.0.

### その他

- The `django.db.backends.postgresql_psycopg2` module is deprecated in favor
  of `django.db.backends.postgresql`. It's been an alias since Django 1.9.
  This only affects code that imports from the module directly. The
  `DATABASES` setting can still use
  `'django.db.backends.postgresql_psycopg2'`, though you can simplify that by
  using the `'django.db.backends.postgresql'` name added in Django 1.9.
- `django.shortcuts.render_to_response()` is deprecated in favor of
  [`django.shortcuts.render()`](/ja/6.0/topics/http/shortcuts/#django.shortcuts.render). `render()` takes the same arguments
  except that it also requires a `request`.
- The `DEFAULT_CONTENT_TYPE` setting is deprecated. It doesn't interact well
  with third-party apps and is obsolete since HTML5 has mostly superseded
  XHTML.
- `HttpRequest.xreadlines()` is deprecated in favor of iterating over the
  request.
- The `field_name` keyword argument to [`QuerySet.earliest()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.earliest) and
  [`QuerySet.latest()`](/ja/6.0/ref/models/querysets/#django.db.models.query.QuerySet.latest) is deprecated in favor of passing the field
  names as arguments. Write `.earliest('pub_date')` instead of
  `.earliest(field_name='pub_date')`.

## 2.0 で削除された機能

以下の機能は、非推奨サイクルの終わりに達したため、Django 2.0 で削除されます。

詳しくは [Features deprecated in 1.9](/ja/6.0/releases/1.9/#deprecated-features-1-9) を見てください。ここには、プロジェクトからこれらの機能を削除する方法についても書かれています。

- `django.dispatch.signals.Signal.disconnect()` から `weak` 引数が削除されました。
- `django.db.backends.base.BaseDatabaseOperations.check_aggregate_support()` が削除されました。
- `django.forms.extras` パッケージが削除されました。
- `assignment_tag` ヘルパーが削除されました。
- `SimpleTestCase.assertsRedirects()` の `host` 引数が削除されました。絶対 URL が相対 URL と同一の場合に、相対 URL と等価なものと解釈する互換レイヤーも削除されました。
- `Field.rel` および `Field.remote_field.to` が削除されました。
- `ForeignKey` および `OneToOneField` の `on_delete` 引数が削除され、新たにモデルとマイグレーションが必須になりました。更新が必要になるマイグレーションの数を少なくするために、マイグレーションを圧縮すること (squashing migrations) を検討してください。
- `django.db.models.fields.add_lazy_relation()` が削除されました。
- When time zone support is enabled, database backends that don't support time
  zones no longer convert aware datetimes to naive values in UTC anymore when
  such values are passed as parameters to SQL queries executed outside of the
  ORM, e.g. with `cursor.execute()`.
- `django.contrib.auth.tests.utils.skipIfCustomUser()` が削除されました。
- `GeoManager` および `GeoQuerySet` クラスが削除されました。
- `django.contrib.gis.geoip` モジュールが削除されました。
- 以下のテンプレートローダーから `supports_recursion` チェックが削除されました。

  - `django.template.engine.Engine.find_template()`
  - `django.template.loader_tags.ExtendsNode.find_template()`
  - `django.template.loaders.base.Loader.supports_recursion()`
  - `django.template.loaders.cached.Loader.supports_recursion()`
- `load_template` および `load_template_sources` テンプレートローダーメソッドが削除されました。
- 以下のテンプレートローダーから `template_dirs` 引数が削除されました。

  - `django.template.loaders.base.Loader.get_template()`
  - `django.template.loaders.cached.Loader.cache_key()`
  - `django.template.loaders.cached.Loader.get_template()`
  - `django.template.loaders.cached.Loader.get_template_sources()`
  - `django.template.loaders.filesystem.Loader.get_template_sources()`
- `django.template.loaders.base.Loader.__call__()` が削除されました。
- `exception` 引数を受け付けない自作のエラービューのサポートが終了しました。
- `django.utils.feedgenerator.Atom1Feed` および `django.utils.feedgenerator.RssFeed` の `mime_type` 属性が削除されました。
- `include()` の `app_name` 引数が削除されました。
- (including `admin.site.urls`) as the first argument to `include()` の1番目の引数として、`admin.site.urls` を含む3タプルを受け取る機能が削除されました。
- アプリケーションの名前空間が存在しない URL インスタンスの名前空間を設定する機能が削除されました。
- `Field._get_val_from_obj()` が削除されました。
- `django.template.loaders.eggs.Loader` が削除されました。
- `contrib.auth` 関数ベースビューの `current_app` 引数が削除されました。
- `SimpleTestCase.assertRaisesMessage()` の `callable_obj` キーワード引数が削除されました。
- `ModelAdmin` メソッドの `allow_tags` 属性のサポートが削除されました。
- `SyndicationFeed.add_item()` の `enclosure` キーワード引数が削除されました。
- `django.template.base.Origin` から `django.template.loader.LoaderOrigin` および `django.template.base.StringOrigin` エイリアスが削除されました。

以下の変更の詳細については、[1.10 で非推奨になった機能](/ja/6.0/releases/1.10/#deprecated-features-1-10) を見てください。

- `makemigrations --exit` オプションが削除されました。
- 逆参照外部キー (reverse foreign key) または many-to-many リレーションに対する値の直接代入のサポートが削除されました。
- `django.contrib.gis.geos.GEOSGeometry` の `get_srid()` と `set_srid()` メソッドが削除されました。
- `django.contrib.gis.geos.Point` の `get_x()` 、 `set_x()` 、 `get_y()` 、 `set_y()` 、 `get_z()` 、 `set_z()` の各メソッドが削除されました。
- `django.contrib.gis.geos.Point` の `get_coords()` と `set_coords()` メソッドが削除されました。
- `django.contrib.gis.geos.MultiPolygon` の `cascaded_union` プロパティが削除されました。
- `django.utils.functional.allow_lazy()` が削除されました。
- `shell --plain` オプションが削除されました。
- `django.core.urlresolvers` モジュールが削除され、新しい場所 `django.urls` に移動しました。
- `CommaSeparatedIntegerField` が削除されました。ただし、履歴マイグレーション (historical migrations) のみ、継続してサポートします。
- テンプレートの `Context.has_key()` メソッドが削除されました。
- `django.core.files.storage.Storage.accessed_time()`、`created_time()`、および `modified_time()` メソッドのサポートが削除されました。
- `default_related_name` が設定されていた場合に、モデル名をクエリー・ルックアップとして使用する機能のサポートが削除されました。
- MySQL の `__search` ルックアップが削除されました。
- `_apply_rel_filters()` メソッドを持たない自作の related manager class をサポートするための shim が削除されました。
- `User.is_authenticated()` と `User.is_anonymous()` をプロパティではなくメソッドをして使う機能はサポートされなくなりました。
- `Model._meta.virtual_fields` 属性が削除されました。
- `Field.contribute_to_class()` の `virtual_only` キーワード引数と、`Model._meta.add_field()` の `virtual` キーワード引数が削除されました。
- `javascript_catalog()` と `json_catalog()` ビューが削除されました。
- `django.contrib.gis.utils.precision_wkt()` が削除されました。
- マルチテーブル継承において、`OneToOneField` を暗黙的に `parent_link` に変換する機能を削除しました。
- `Widget._format_value()` のサポートが削除されました。
- `FileField` の `get_directory_name()` および `get_filename()` メソッドが削除されました。
- `mark_for_escaping()` 関数と、この関数を使用するクラス `EscapeData`、`EscapeBytes`、`EscapeText`、`EscapeString`、および `EscapeUnicode` が削除されました。
- `escape` フィルタが新らしく `django.utils.html.conditional_escape()` を使用するようになりました。
- `Manager.use_for_related_fields` が削除されました。
- Model `Manager` inheritance follows MRO inheritance rules. The requirement
  to use `Meta.manager_inheritance_from_future` to opt-in to the behavior is
  removed.
- `settings.MIDDLEWARE_CLASSES` を使用した古いスタイルのミドルウェアのサポートが削除されました。
