1. ========================
    
  2. Django 2.0 release notes
    
  3. ========================
    
  4. 
    
  5. *December 2, 2017*
    
  6. 
    
  7. Welcome to Django 2.0!
    
  8. 
    
  9. These release notes cover the :ref:`new features <whats-new-2.0>`, as well as
    
  10. some :ref:`backwards incompatible changes <backwards-incompatible-2.0>` you'll
    
  11. want to be aware of when upgrading from Django 1.11 or earlier. We've
    
  12. :ref:`dropped some features<removed-features-2.0>` that have reached the end of
    
  13. their deprecation cycle, and we've :ref:`begun the deprecation process for some
    
  14. features <deprecated-features-2.0>`.
    
  15. 
    
  16. This release starts Django's use of a :ref:`loose form of semantic versioning
    
  17. <internal-release-cadence>`, but there aren't any major backwards incompatible
    
  18. changes that might be expected of a 2.0 release. Upgrading should be a similar
    
  19. amount of effort as past feature releases.
    
  20. 
    
  21. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
    
  22. project.
    
  23. 
    
  24. Python compatibility
    
  25. ====================
    
  26. 
    
  27. Django 2.0 supports Python 3.4, 3.5, 3.6, and 3.7. We **highly recommend** and
    
  28. only officially support the latest release of each series.
    
  29. 
    
  30. The Django 1.11.x series is the last to support Python 2.7.
    
  31. 
    
  32. Django 2.0 will be the last release series to support Python 3.4. If you plan
    
  33. a deployment of Python 3.4 beyond the end-of-life for Django 2.0 (April 2019),
    
  34. stick with Django 1.11 LTS (supported until April 2020) instead. Note, however,
    
  35. that the end-of-life for Python 3.4 is March 2019.
    
  36. 
    
  37. Third-party library support for older version of Django
    
  38. =======================================================
    
  39. 
    
  40. Following the release of Django 2.0, we suggest that third-party app authors
    
  41. drop support for all versions of Django prior to 1.11. At that time, you should
    
  42. be able to run your package's tests using ``python -Wd`` so that deprecation
    
  43. warnings do appear. After making the deprecation warning fixes, your app should
    
  44. be compatible with Django 2.0.
    
  45. 
    
  46. .. _whats-new-2.0:
    
  47. 
    
  48. What's new in Django 2.0
    
  49. ========================
    
  50. 
    
  51. Simplified URL routing syntax
    
  52. -----------------------------
    
  53. 
    
  54. The new :func:`django.urls.path()` function allows a simpler, more readable URL
    
  55. routing syntax. For example, this example from previous Django releases::
    
  56. 
    
  57.     url(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive),
    
  58. 
    
  59. could be written as::
    
  60. 
    
  61.     path('articles/<int:year>/', views.year_archive),
    
  62. 
    
  63. The new syntax supports type coercion of URL parameters. In the example, the
    
  64. view will receive the ``year`` keyword argument as an integer rather than as
    
  65. a string. Also, the URLs that will match are slightly less constrained in the
    
  66. rewritten example. For example, the year 10000 will now match since the year
    
  67. integers aren't constrained to be exactly four digits long as they are in the
    
  68. regular expression.
    
  69. 
    
  70. The ``django.conf.urls.url()`` function from previous versions is now available
    
  71. as :func:`django.urls.re_path`. The old location remains for backwards
    
  72. compatibility, without an imminent deprecation. The old
    
  73. ``django.conf.urls.include()`` function is now importable from ``django.urls``
    
  74. so you can use ``from django.urls import include, path, re_path`` in your
    
  75. URLconfs.
    
  76. 
    
  77. The :doc:`/topics/http/urls` document is rewritten to feature the new syntax
    
  78. and provide more details.
    
  79. 
    
  80. Mobile-friendly ``contrib.admin``
    
  81. ---------------------------------
    
  82. 
    
  83. The admin is now responsive and supports all major mobile devices. Older
    
  84. browsers may experience varying levels of graceful degradation.
    
  85. 
    
  86. Window expressions
    
  87. ------------------
    
  88. 
    
  89. The new :class:`~django.db.models.expressions.Window` expression allows
    
  90. adding an ``OVER`` clause to querysets. You can use :ref:`window functions
    
  91. <window-functions>` and :ref:`aggregate functions <aggregation-functions>` in
    
  92. the expression.
    
  93. 
    
  94. Minor features
    
  95. --------------
    
  96. 
    
  97. :mod:`django.contrib.admin`
    
  98. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  99. 
    
  100. * The new :attr:`.ModelAdmin.autocomplete_fields` attribute and
    
  101.   :meth:`.ModelAdmin.get_autocomplete_fields` method allow using a
    
  102.   `Select2 <https://select2.org/>`_ search widget for ``ForeignKey`` and
    
  103.   ``ManyToManyField``.
    
  104. 
    
  105. :mod:`django.contrib.auth`
    
  106. ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  107. 
    
  108. * The default iteration count for the PBKDF2 password hasher is increased from
    
  109.   36,000 to 100,000.
    
  110. 
    
  111. :mod:`django.contrib.gis`
    
  112. ~~~~~~~~~~~~~~~~~~~~~~~~~
    
  113. 
    
  114. * Added MySQL support for the
    
  115.   :class:`~django.contrib.gis.db.models.functions.AsGeoJSON` function,
    
  116.   :class:`~django.contrib.gis.db.models.functions.GeoHash` function,
    
  117.   :class:`~django.contrib.gis.db.models.functions.IsValid` function,
    
  118.   :lookup:`isvalid` lookup, and :ref:`distance lookups <distance-lookups>`.
    
  119. 
    
  120. * Added the :class:`~django.contrib.gis.db.models.functions.Azimuth` and
    
  121.   :class:`~django.contrib.gis.db.models.functions.LineLocatePoint` functions,
    
  122.   supported on PostGIS and SpatiaLite.
    
  123. 
    
  124. * Any :class:`~django.contrib.gis.geos.GEOSGeometry` imported from GeoJSON now
    
  125.   has its SRID set.
    
  126. 
    
  127. * Added the :attr:`.OSMWidget.default_zoom` attribute to customize the map's
    
  128.   default zoom level.
    
  129. 
    
  130. * Made metadata readable and editable on rasters through the
    
  131.   :attr:`~django.contrib.gis.gdal.GDALRaster.metadata`,
    
  132.   :attr:`~django.contrib.gis.gdal.GDALRaster.info`, and
    
  133.   :attr:`~django.contrib.gis.gdal.GDALBand.metadata` attributes.
    
  134. 
    
  135. * Allowed passing driver-specific creation options to
    
  136.   :class:`~django.contrib.gis.gdal.GDALRaster` objects using ``papsz_options``.
    
  137. 
    
  138. * Allowed creating :class:`~django.contrib.gis.gdal.GDALRaster` objects in
    
  139.   GDAL's internal virtual filesystem. Rasters can now be :ref:`created from and
    
  140.   converted to binary data <gdal-raster-vsimem>` in-memory.
    
  141. 
    
  142. * The new :meth:`GDALBand.color_interp()
    
  143.   <django.contrib.gis.gdal.GDALBand.color_interp>` method returns the color
    
  144.   interpretation for the band.
    
  145. 
    
  146. :mod:`django.contrib.postgres`
    
  147. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  148. 
    
  149. * The new ``distinct`` argument for
    
  150.   :class:`~django.contrib.postgres.aggregates.ArrayAgg` determines if
    
  151.   concatenated values will be distinct.
    
  152. 
    
  153. * The new :class:`~django.contrib.postgres.functions.RandomUUID` database
    
  154.   function returns a version 4 UUID. It requires use of PostgreSQL's
    
  155.   ``pgcrypto`` extension which can be activated using the new
    
  156.   :class:`~django.contrib.postgres.operations.CryptoExtension` migration
    
  157.   operation.
    
  158. 
    
  159. * :class:`django.contrib.postgres.indexes.GinIndex` now supports the
    
  160.   ``fastupdate`` and ``gin_pending_list_limit`` parameters.
    
  161. 
    
  162. * The new :class:`~django.contrib.postgres.indexes.GistIndex` class allows
    
  163.   creating ``GiST`` indexes in the database. The new
    
  164.   :class:`~django.contrib.postgres.operations.BtreeGistExtension` migration
    
  165.   operation installs the ``btree_gist`` extension to add support for operator
    
  166.   classes that aren't built-in.
    
  167. 
    
  168. * :djadmin:`inspectdb` can now introspect ``JSONField`` and various
    
  169.   ``RangeField``\s (``django.contrib.postgres`` must be in ``INSTALLED_APPS``).
    
  170. 
    
  171. :mod:`django.contrib.sitemaps`
    
  172. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  173. 
    
  174. * Added the ``protocol`` keyword argument to the
    
  175.   :class:`~django.contrib.sitemaps.GenericSitemap` constructor.
    
  176. 
    
  177. Cache
    
  178. ~~~~~
    
  179. 
    
  180. * ``cache.set_many()`` now returns a list of keys that failed to be inserted.
    
  181.   For the built-in backends, failed inserts can only happen on memcached.
    
  182. 
    
  183. File Storage
    
  184. ~~~~~~~~~~~~
    
  185. 
    
  186. * :meth:`File.open() <django.core.files.File.open>` can be used as a context
    
  187.   manager, e.g. ``with file.open() as f:``.
    
  188. 
    
  189. Forms
    
  190. ~~~~~
    
  191. 
    
  192. * The new ``date_attrs`` and ``time_attrs`` arguments for
    
  193.   :class:`~django.forms.SplitDateTimeWidget` and
    
  194.   :class:`~django.forms.SplitHiddenDateTimeWidget` allow specifying different
    
  195.   HTML attributes for the ``DateInput`` and ``TimeInput`` (or hidden)
    
  196.   subwidgets.
    
  197. 
    
  198. * The new :meth:`Form.errors.get_json_data()
    
  199.   <django.forms.Form.errors.get_json_data>` method returns form errors as
    
  200.   a dictionary suitable for including in a JSON response.
    
  201. 
    
  202. Generic Views
    
  203. ~~~~~~~~~~~~~
    
  204. 
    
  205. * The new :attr:`.ContextMixin.extra_context` attribute allows adding context
    
  206.   in ``View.as_view()``.
    
  207. 
    
  208. Management Commands
    
  209. ~~~~~~~~~~~~~~~~~~~
    
  210. 
    
  211. * :djadmin:`inspectdb` now translates MySQL's unsigned integer columns to
    
  212.   ``PositiveIntegerField`` or ``PositiveSmallIntegerField``.
    
  213. 
    
  214. * The new :option:`makemessages --add-location` option controls the comment
    
  215.   format in ``.po`` files.
    
  216. 
    
  217. * :djadmin:`loaddata` can now :ref:`read from stdin <loading-fixtures-stdin>`.
    
  218. 
    
  219. * The new :option:`diffsettings --output` option allows formatting the output
    
  220.   in a unified diff format.
    
  221. 
    
  222. * On Oracle, :djadmin:`inspectdb` can now introspect ``AutoField`` if the
    
  223.   column is created as an identity column.
    
  224. 
    
  225. * On MySQL, :djadmin:`dbshell` now supports client-side TLS certificates.
    
  226. 
    
  227. Migrations
    
  228. ~~~~~~~~~~
    
  229. 
    
  230. * The new :option:`squashmigrations --squashed-name` option allows naming the
    
  231.   squashed migration.
    
  232. 
    
  233. Models
    
  234. ~~~~~~
    
  235. 
    
  236. * The new :class:`~django.db.models.functions.StrIndex` database function
    
  237.   finds the starting index of a string inside another string.
    
  238. 
    
  239. * On Oracle, ``AutoField`` and ``BigAutoField`` are now created as `identity
    
  240.   columns <https://docs.oracle.com/en/database/oracle/oracle-database/21/drdaa/
    
  241.   intro-to-tools-and-products-supporting-migraiton.html#GUID-14E4817B-F3BC-4D99
    
  242.   -B471-A0ACDC303CC9>`__.
    
  243. 
    
  244. * The new ``chunk_size`` parameter of :meth:`.QuerySet.iterator` controls the
    
  245.   number of rows fetched by the Python database client when streaming results
    
  246.   from the database. For databases that don't support server-side cursors, it
    
  247.   controls the number of results Django fetches from the database adapter.
    
  248. 
    
  249. * :meth:`.QuerySet.earliest`, :meth:`.QuerySet.latest`, and
    
  250.   :attr:`Meta.get_latest_by <django.db.models.Options.get_latest_by>` now
    
  251.   allow ordering by several fields.
    
  252. 
    
  253. * Added the :class:`~django.db.models.functions.ExtractQuarter` function to
    
  254.   extract the quarter from :class:`~django.db.models.DateField` and
    
  255.   :class:`~django.db.models.DateTimeField`, and exposed it through the
    
  256.   :lookup:`quarter` lookup.
    
  257. 
    
  258. * Added the :class:`~django.db.models.functions.TruncQuarter` function to
    
  259.   truncate :class:`~django.db.models.DateField` and
    
  260.   :class:`~django.db.models.DateTimeField` to the first day of a quarter.
    
  261. 
    
  262. * Added the :attr:`~django.db.models.Index.db_tablespace` parameter to
    
  263.   class-based indexes.
    
  264. 
    
  265. * If the database supports a native duration field (Oracle and PostgreSQL),
    
  266.   :class:`~django.db.models.functions.Extract` now works with
    
  267.   :class:`~django.db.models.DurationField`.
    
  268. 
    
  269. * Added the ``of`` argument to :meth:`.QuerySet.select_for_update()`, supported
    
  270.   on PostgreSQL and Oracle, to lock only rows from specific tables rather than
    
  271.   all selected tables. It may be helpful particularly when
    
  272.   :meth:`~.QuerySet.select_for_update()` is used in conjunction with
    
  273.   :meth:`~.QuerySet.select_related()`.
    
  274. 
    
  275. * The new ``field_name`` parameter of :meth:`.QuerySet.in_bulk` allows fetching
    
  276.   results based on any unique model field.
    
  277. 
    
  278. * :meth:`.CursorWrapper.callproc()` now takes an optional dictionary of keyword
    
  279.   parameters, if the backend supports this feature. Of Django's built-in
    
  280.   backends, only Oracle supports it.
    
  281. 
    
  282. * The new :meth:`connection.execute_wrapper()
    
  283.   <django.db.backends.base.DatabaseWrapper.execute_wrapper>` method allows
    
  284.   :doc:`installing wrappers around execution of database queries
    
  285.   </topics/db/instrumentation>`.
    
  286. 
    
  287. * The new ``filter`` argument for built-in aggregates allows :ref:`adding
    
  288.   different conditionals <conditional-aggregation>` to multiple aggregations
    
  289.   over the same fields or relations.
    
  290. 
    
  291. * Added support for expressions in :attr:`Meta.ordering
    
  292.   <django.db.models.Options.ordering>`.
    
  293. 
    
  294. * The new ``named`` parameter of :meth:`.QuerySet.values_list` allows fetching
    
  295.   results as named tuples.
    
  296. 
    
  297. * The new :class:`.FilteredRelation` class allows adding an ``ON`` clause to
    
  298.   querysets.
    
  299. 
    
  300. Pagination
    
  301. ~~~~~~~~~~
    
  302. 
    
  303. * Added :meth:`Paginator.get_page() <django.core.paginator.Paginator.get_page>`
    
  304.   to provide the documented pattern of handling invalid page numbers.
    
  305. 
    
  306. Requests and Responses
    
  307. ~~~~~~~~~~~~~~~~~~~~~~
    
  308. 
    
  309. * The :djadmin:`runserver` web server supports HTTP 1.1.
    
  310. 
    
  311. Templates
    
  312. ~~~~~~~~~
    
  313. 
    
  314. * To increase the usefulness of :meth:`.Engine.get_default` in third-party
    
  315.   apps, it now returns the first engine if multiple ``DjangoTemplates`` engines
    
  316.   are configured in ``TEMPLATES`` rather than raising ``ImproperlyConfigured``.
    
  317. 
    
  318. * Custom template tags may now accept keyword-only arguments.
    
  319. 
    
  320. Tests
    
  321. ~~~~~
    
  322. 
    
  323. * Added threading support to :class:`~django.test.LiveServerTestCase`.
    
  324. 
    
  325. * Added settings that allow customizing the test tablespace parameters for
    
  326.   Oracle: :setting:`DATAFILE_SIZE`, :setting:`DATAFILE_TMP_SIZE`,
    
  327.   :setting:`DATAFILE_EXTSIZE`, and :setting:`DATAFILE_TMP_EXTSIZE`.
    
  328. 
    
  329. Validators
    
  330. ~~~~~~~~~~
    
  331. 
    
  332. * The new :class:`.ProhibitNullCharactersValidator` disallows the null
    
  333.   character in the input of the :class:`~django.forms.CharField` form field
    
  334.   and its subclasses. Null character input was observed from vulnerability
    
  335.   scanning tools. Most databases silently discard null characters, but
    
  336.   psycopg2 2.7+ raises an exception when trying to save a null character to
    
  337.   a char/text field with PostgreSQL.
    
  338. 
    
  339. .. _backwards-incompatible-2.0:
    
  340. 
    
  341. Backwards incompatible changes in 2.0
    
  342. =====================================
    
  343. 
    
  344. Removed support for bytestrings in some places
    
  345. ----------------------------------------------
    
  346. 
    
  347. To support native Python 2 strings, older Django versions had to accept both
    
  348. bytestrings and Unicode strings. Now that Python 2 support is dropped,
    
  349. bytestrings should only be encountered around input/output boundaries (handling
    
  350. of binary fields or HTTP streams, for example). You might have to update your
    
  351. code to limit bytestring usage to a minimum, as Django no longer accepts
    
  352. bytestrings in certain code paths. Python's :option:`-b` option may help detect
    
  353. that mistake in your code.
    
  354. 
    
  355. For example, ``reverse()`` now uses ``str()`` instead of ``force_text()`` to
    
  356. coerce the ``args`` and ``kwargs`` it receives, prior to their placement in
    
  357. the URL. For bytestrings, this creates a string with an undesired ``b`` prefix
    
  358. as well as additional quotes (``str(b'foo')`` is ``"b'foo'"``). To adapt, call
    
  359. ``decode()`` on the bytestring before passing it to ``reverse()``.
    
  360. 
    
  361. Database backend API
    
  362. --------------------
    
  363. 
    
  364. This section describes changes that may be needed in third-party database
    
  365. backends.
    
  366. 
    
  367. * The ``DatabaseOperations.datetime_cast_date_sql()``,
    
  368.   ``datetime_cast_time_sql()``, ``datetime_trunc_sql()``,
    
  369.   ``datetime_extract_sql()``, and ``date_interval_sql()`` methods now return
    
  370.   only the SQL to perform the operation instead of SQL and a list of
    
  371.   parameters.
    
  372. 
    
  373. * Third-party database backends should add a ``DatabaseWrapper.display_name``
    
  374.   attribute with the name of the database that your backend works with. Django
    
  375.   may use it in various messages, such as in system checks.
    
  376. 
    
  377. * The first argument of ``SchemaEditor._alter_column_type_sql()`` is now
    
  378.   ``model`` rather than ``table``.
    
  379. 
    
  380. * The first argument of ``SchemaEditor._create_index_name()`` is now
    
  381.   ``table_name`` rather than ``model``.
    
  382. 
    
  383. * To enable ``FOR UPDATE OF`` support, set
    
  384.   ``DatabaseFeatures.has_select_for_update_of = True``. If the database
    
  385.   requires that the arguments to ``OF`` be columns rather than tables, set
    
  386.   ``DatabaseFeatures.select_for_update_of_column = True``.
    
  387. 
    
  388. * To enable support for :class:`~django.db.models.expressions.Window`
    
  389.   expressions, set ``DatabaseFeatures.supports_over_clause`` to ``True``. You
    
  390.   may need to customize the ``DatabaseOperations.window_start_rows_start_end()``
    
  391.   and/or ``window_start_range_start_end()`` methods.
    
  392. 
    
  393. * Third-party database backends should add a
    
  394.   ``DatabaseOperations.cast_char_field_without_max_length`` attribute with the
    
  395.   database data type that will be used in the
    
  396.   :class:`~django.db.models.functions.Cast` function for a ``CharField`` if the
    
  397.   ``max_length`` argument isn't provided.
    
  398. 
    
  399. * The first argument of ``DatabaseCreation._clone_test_db()`` and
    
  400.   ``get_test_db_clone_settings()`` is now ``suffix`` rather
    
  401.   than ``number`` (in case you want to rename the signatures in your backend
    
  402.   for consistency). ``django.test`` also now passes those values as strings
    
  403.   rather than as integers.
    
  404. 
    
  405. * Third-party database backends should add a
    
  406.   ``DatabaseIntrospection.get_sequences()`` method based on the stub in
    
  407.   ``BaseDatabaseIntrospection``.
    
  408. 
    
  409. Dropped support for Oracle 11.2
    
  410. -------------------------------
    
  411. 
    
  412. The end of upstream support for Oracle 11.2 is Dec. 2020. Django 1.11 will be
    
  413. supported until April 2020 which almost reaches this date. Django 2.0
    
  414. officially supports Oracle 12.1+.
    
  415. 
    
  416. Default MySQL isolation level is read committed
    
  417. -----------------------------------------------
    
  418. 
    
  419. MySQL's default isolation level, repeatable read, may cause data loss in
    
  420. typical Django usage. To prevent that and for consistency with other databases,
    
  421. the default isolation level is now read committed. You can use the
    
  422. :setting:`DATABASES` setting to :ref:`use a different isolation level
    
  423. <mysql-isolation-level>`, if needed.
    
  424. 
    
  425. :attr:`AbstractUser.last_name <django.contrib.auth.models.User.last_name>` ``max_length`` increased to 150
    
  426. ----------------------------------------------------------------------------------------------------------
    
  427. 
    
  428. A migration for :attr:`django.contrib.auth.models.User.last_name` is included.
    
  429. If you have a custom user model inheriting from ``AbstractUser``, you'll need
    
  430. to generate and apply a database migration for your user model.
    
  431. 
    
  432. If you want to preserve the 30 character limit for last names, use a custom
    
  433. form::
    
  434. 
    
  435.     from django.contrib.auth.forms import UserChangeForm
    
  436. 
    
  437.     class MyUserChangeForm(UserChangeForm):
    
  438.         last_name = forms.CharField(max_length=30, required=False)
    
  439. 
    
  440. If you wish to keep this restriction in the admin when editing users, set
    
  441. ``UserAdmin.form`` to use this form::
    
  442. 
    
  443.     from django.contrib.auth.admin import UserAdmin
    
  444.     from django.contrib.auth.models import User
    
  445. 
    
  446.     class MyUserAdmin(UserAdmin):
    
  447.         form = MyUserChangeForm
    
  448. 
    
  449.     admin.site.unregister(User)
    
  450.     admin.site.register(User, MyUserAdmin)
    
  451. 
    
  452. ``QuerySet.reverse()`` and ``last()`` are prohibited after slicing
    
  453. ------------------------------------------------------------------
    
  454. 
    
  455. Calling ``QuerySet.reverse()`` or ``last()`` on a sliced queryset leads to
    
  456. unexpected results due to the slice being applied after reordering. This is
    
  457. now prohibited, e.g.::
    
  458. 
    
  459.     >>> Model.objects.all()[:2].reverse()
    
  460.     Traceback (most recent call last):
    
  461.     ...
    
  462.     TypeError: Cannot reverse a query once a slice has been taken.
    
  463. 
    
  464. Form fields no longer accept optional arguments as positional arguments
    
  465. -----------------------------------------------------------------------
    
  466. 
    
  467. To help prevent runtime errors due to incorrect ordering of form field
    
  468. arguments, optional arguments of built-in form fields are no longer accepted
    
  469. as positional arguments. For example::
    
  470. 
    
  471.     forms.IntegerField(25, 10)
    
  472. 
    
  473. raises an exception and should be replaced with::
    
  474. 
    
  475.     forms.IntegerField(max_value=25, min_value=10)
    
  476. 
    
  477. ``call_command()`` validates the options it receives
    
  478. ----------------------------------------------------
    
  479. 
    
  480. ``call_command()`` now validates that the argument parser of the command being
    
  481. called defines all of the options passed to ``call_command()``.
    
  482. 
    
  483. For custom management commands that use options not created using
    
  484. ``parser.add_argument()``, add a ``stealth_options`` attribute on the command::
    
  485. 
    
  486.     class MyCommand(BaseCommand):
    
  487.         stealth_options = ('option_name', ...)
    
  488. 
    
  489. Indexes no longer accept positional arguments
    
  490. ---------------------------------------------
    
  491. 
    
  492. For example::
    
  493. 
    
  494.     models.Index(['headline', '-pub_date'], 'index_name')
    
  495. 
    
  496. raises an exception and should be replaced with::
    
  497. 
    
  498.     models.Index(fields=['headline', '-pub_date'], name='index_name')
    
  499. 
    
  500. Foreign key constraints are now enabled on SQLite
    
  501. -------------------------------------------------
    
  502. 
    
  503. This will appear as a backwards-incompatible change (``IntegrityError:
    
  504. FOREIGN KEY constraint failed``) if attempting to save an existing model
    
  505. instance that's violating a foreign key constraint.
    
  506. 
    
  507. Foreign keys are now created with ``DEFERRABLE INITIALLY DEFERRED`` instead of
    
  508. ``DEFERRABLE IMMEDIATE``. Thus, tables may need to be rebuilt to recreate
    
  509. foreign keys with the new definition, particularly if you're using a pattern
    
  510. like this::
    
  511. 
    
  512.     from django.db import transaction
    
  513. 
    
  514.     with transaction.atomic():
    
  515.         Book.objects.create(author_id=1)
    
  516.         Author.objects.create(id=1)
    
  517. 
    
  518. If you don't recreate the foreign key as ``DEFERRED``, the first ``create()``
    
  519. would fail now that foreign key constraints are enforced.
    
  520. 
    
  521. Backup your database first! After upgrading to Django 2.0, you can then
    
  522. rebuild tables using a script similar to this::
    
  523. 
    
  524.     from django.apps import apps
    
  525.     from django.db import connection
    
  526. 
    
  527.     for app in apps.get_app_configs():
    
  528.         for model in app.get_models(include_auto_created=True):
    
  529.             if model._meta.managed and not (model._meta.proxy or model._meta.swapped):
    
  530.                 for base in model.__bases__:
    
  531.                     if hasattr(base, '_meta'):
    
  532.                         base._meta.local_many_to_many = []
    
  533.                 model._meta.local_many_to_many = []
    
  534.                 with connection.schema_editor() as editor:
    
  535.                     editor._remake_table(model)
    
  536. 
    
  537. This script hasn't received extensive testing and needs adaption for various
    
  538. cases such as multiple databases. Feel free to contribute improvements.
    
  539. 
    
  540. In addition, because of a table alteration limitation of SQLite, it's prohibited
    
  541. to perform :class:`~django.db.migrations.operations.RenameModel` and
    
  542. :class:`~django.db.migrations.operations.RenameField` operations on models or
    
  543. fields referenced by other models in a transaction. In order to allow migrations
    
  544. containing these operations to be applied, you must set the
    
  545. ``Migration.atomic`` attribute to ``False``.
    
  546. 
    
  547. Miscellaneous
    
  548. -------------
    
  549. 
    
  550. * The ``SessionAuthenticationMiddleware`` class is removed. It provided no
    
  551.   functionality since session authentication is unconditionally enabled in
    
  552.   Django 1.10.
    
  553. 
    
  554. * The default HTTP error handlers (``handler404``, etc.) are now callables
    
  555.   instead of dotted Python path strings. Django favors callable references
    
  556.   since they provide better performance and debugging experience.
    
  557. 
    
  558. * :class:`~django.views.generic.base.RedirectView` no longer silences
    
  559.   ``NoReverseMatch`` if the ``pattern_name`` doesn't exist.
    
  560. 
    
  561. * When ``USE_L10N`` is off, :class:`~django.forms.FloatField` and
    
  562.   :class:`~django.forms.DecimalField` now respect :setting:`DECIMAL_SEPARATOR`
    
  563.   and :setting:`THOUSAND_SEPARATOR` during validation. For example, with the
    
  564.   settings::
    
  565. 
    
  566.      USE_L10N = False
    
  567.      USE_THOUSAND_SEPARATOR = True
    
  568.      DECIMAL_SEPARATOR = ','
    
  569.      THOUSAND_SEPARATOR = '.'
    
  570. 
    
  571.   an input of ``"1.345"`` is now converted to ``1345`` instead of ``1.345``.
    
  572. 
    
  573. * Subclasses of :class:`~django.contrib.auth.models.AbstractBaseUser` are no
    
  574.   longer required to implement ``get_short_name()`` and ``get_full_name()``.
    
  575.   (The base implementations that raise ``NotImplementedError`` are removed.)
    
  576.   ``django.contrib.admin`` uses these methods if implemented but doesn't
    
  577.   require them. Third-party apps that use these methods may want to adopt a
    
  578.   similar approach.
    
  579. 
    
  580. * The ``FIRST_DAY_OF_WEEK`` and ``NUMBER_GROUPING`` format settings are now
    
  581.   kept as integers in JavaScript and JSON i18n view outputs.
    
  582. 
    
  583. * :meth:`~django.test.TransactionTestCase.assertNumQueries` now ignores
    
  584.   connection configuration queries. Previously, if a test opened a new database
    
  585.   connection, those queries could be included as part of the
    
  586.   ``assertNumQueries()`` count.
    
  587. 
    
  588. * The default size of the Oracle test tablespace is increased from 20M to 50M
    
  589.   and the default autoextend size is increased from 10M to 25M.
    
  590. 
    
  591. * To improve performance when streaming large result sets from the database,
    
  592.   :meth:`.QuerySet.iterator` now fetches 2000 rows at a time instead of 100.
    
  593.   The old behavior can be restored using the ``chunk_size`` parameter. For
    
  594.   example::
    
  595. 
    
  596.       Book.objects.iterator(chunk_size=100)
    
  597. 
    
  598. * Providing unknown package names in the ``packages`` argument of the
    
  599.   :class:`~django.views.i18n.JavaScriptCatalog` view now raises ``ValueError``
    
  600.   instead of passing silently.
    
  601. 
    
  602. * A model instance's primary key now appears in the default ``Model.__str__()``
    
  603.   method, e.g. ``Question object (1)``.
    
  604. 
    
  605. * ``makemigrations`` now detects changes to the model field ``limit_choices_to``
    
  606.   option. Add this to your existing migrations or accept an auto-generated
    
  607.   migration for fields that use it.
    
  608. 
    
  609. * Performing queries that require :ref:`automatic spatial transformations
    
  610.   <automatic-spatial-transformations>` now raises ``NotImplementedError``
    
  611.   on MySQL instead of silently using non-transformed geometries.
    
  612. 
    
  613. * ``django.core.exceptions.DjangoRuntimeWarning`` is removed. It was only used
    
  614.   in the cache backend as an intermediate class in ``CacheKeyWarning``'s
    
  615.   inheritance of ``RuntimeWarning``.
    
  616. 
    
  617. * Renamed ``BaseExpression._output_field`` to ``output_field``. You may need
    
  618.   to update custom expressions.
    
  619. 
    
  620. * In older versions, forms and formsets combine their ``Media`` with widget
    
  621.   ``Media`` by concatenating the two. The combining now tries to :ref:`preserve
    
  622.   the relative order of elements in each list <form-media-asset-order>`.
    
  623.   ``MediaOrderConflictWarning`` is issued if the order can't be preserved.
    
  624. 
    
  625. * ``django.contrib.gis.gdal.OGRException`` is removed. It's been an alias for
    
  626.   ``GDALException`` since Django 1.8.
    
  627. 
    
  628. * Support for GEOS 3.3.x is dropped.
    
  629. 
    
  630. * The way data is selected for ``GeometryField`` is changed to improve
    
  631.   performance, and in raw SQL queries, those fields must now be wrapped in
    
  632.   ``connection.ops.select``. See the :ref:`Raw queries note<gis-raw-sql>` in
    
  633.   the GIS tutorial for an example.
    
  634. 
    
  635. .. _deprecated-features-2.0:
    
  636. 
    
  637. Features deprecated in 2.0
    
  638. ==========================
    
  639. 
    
  640. ``context`` argument of ``Field.from_db_value()`` and ``Expression.convert_value()``
    
  641. ------------------------------------------------------------------------------------
    
  642. 
    
  643. The ``context`` argument of ``Field.from_db_value()`` and
    
  644. ``Expression.convert_value()`` is unused as it's always an empty dictionary.
    
  645. The signature of both methods is now::
    
  646. 
    
  647.     (self, value, expression, connection)
    
  648. 
    
  649. instead of::
    
  650. 
    
  651.     (self, value, expression, connection, context)
    
  652. 
    
  653. Support for the old signature in custom fields and expressions remains until
    
  654. Django 3.0.
    
  655. 
    
  656. Miscellaneous
    
  657. -------------
    
  658. 
    
  659. * The ``django.db.backends.postgresql_psycopg2`` module is deprecated in favor
    
  660.   of ``django.db.backends.postgresql``. It's been an alias since Django 1.9.
    
  661.   This only affects code that imports from the module directly. The
    
  662.   ``DATABASES`` setting can still use
    
  663.   ``'django.db.backends.postgresql_psycopg2'``, though you can simplify that by
    
  664.   using the ``'django.db.backends.postgresql'`` name added in Django 1.9.
    
  665. 
    
  666. * ``django.shortcuts.render_to_response()`` is deprecated in favor of
    
  667.   :func:`django.shortcuts.render`. ``render()`` takes the same arguments
    
  668.   except that it also requires a ``request``.
    
  669. 
    
  670. * The ``DEFAULT_CONTENT_TYPE`` setting is deprecated. It doesn't interact well
    
  671.   with third-party apps and is obsolete since HTML5 has mostly superseded
    
  672.   XHTML.
    
  673. 
    
  674. * ``HttpRequest.xreadlines()`` is deprecated in favor of iterating over the
    
  675.   request.
    
  676. 
    
  677. * The ``field_name`` keyword argument to :meth:`.QuerySet.earliest` and
    
  678.   :meth:`.QuerySet.latest` is deprecated in favor of passing the field
    
  679.   names as arguments. Write ``.earliest('pub_date')`` instead of
    
  680.   ``.earliest(field_name='pub_date')``.
    
  681. 
    
  682. .. _removed-features-2.0:
    
  683. 
    
  684. Features removed in 2.0
    
  685. =======================
    
  686. 
    
  687. These features have reached the end of their deprecation cycle and are removed
    
  688. in Django 2.0.
    
  689. 
    
  690. See :ref:`deprecated-features-1.9` for details on these changes, including how
    
  691. to remove usage of these features.
    
  692. 
    
  693. * The ``weak`` argument to ``django.dispatch.signals.Signal.disconnect()`` is
    
  694.   removed.
    
  695. 
    
  696. * ``django.db.backends.base.BaseDatabaseOperations.check_aggregate_support()``
    
  697.   is removed.
    
  698. 
    
  699. * The ``django.forms.extras`` package is removed.
    
  700. 
    
  701. * The ``assignment_tag`` helper is removed.
    
  702. 
    
  703. * The ``host`` argument to ``SimpleTestCase.assertsRedirects()`` is removed.
    
  704.   The compatibility layer which allows absolute URLs to be considered equal to
    
  705.   relative ones when the path is identical is also removed.
    
  706. 
    
  707. * ``Field.rel`` and ``Field.remote_field.to`` are removed.
    
  708. 
    
  709. * The ``on_delete`` argument for ``ForeignKey`` and ``OneToOneField`` is now
    
  710.   required in models and migrations. Consider squashing migrations so that you
    
  711.   have fewer of them to update.
    
  712. 
    
  713. * ``django.db.models.fields.add_lazy_relation()`` is removed.
    
  714. 
    
  715. * When time zone support is enabled, database backends that don't support time
    
  716.   zones no longer convert aware datetimes to naive values in UTC anymore when
    
  717.   such values are passed as parameters to SQL queries executed outside of the
    
  718.   ORM, e.g. with ``cursor.execute()``.
    
  719. 
    
  720. * ``django.contrib.auth.tests.utils.skipIfCustomUser()`` is removed.
    
  721. 
    
  722. * The ``GeoManager`` and ``GeoQuerySet`` classes are removed.
    
  723. 
    
  724. * The ``django.contrib.gis.geoip`` module is removed.
    
  725. 
    
  726. * The ``supports_recursion`` check for template loaders is removed from:
    
  727. 
    
  728.   * ``django.template.engine.Engine.find_template()``
    
  729.   * ``django.template.loader_tags.ExtendsNode.find_template()``
    
  730.   * ``django.template.loaders.base.Loader.supports_recursion()``
    
  731.   * ``django.template.loaders.cached.Loader.supports_recursion()``
    
  732. 
    
  733. * The ``load_template`` and ``load_template_sources`` template loader methods
    
  734.   are removed.
    
  735. 
    
  736. * The ``template_dirs`` argument for template loaders is removed:
    
  737. 
    
  738.   * ``django.template.loaders.base.Loader.get_template()``
    
  739.   * ``django.template.loaders.cached.Loader.cache_key()``
    
  740.   * ``django.template.loaders.cached.Loader.get_template()``
    
  741.   * ``django.template.loaders.cached.Loader.get_template_sources()``
    
  742.   * ``django.template.loaders.filesystem.Loader.get_template_sources()``
    
  743. 
    
  744. * ``django.template.loaders.base.Loader.__call__()`` is removed.
    
  745. 
    
  746. * Support for custom error views that don't accept an ``exception`` parameter
    
  747.   is removed.
    
  748. 
    
  749. * The ``mime_type`` attribute of ``django.utils.feedgenerator.Atom1Feed`` and
    
  750.   ``django.utils.feedgenerator.RssFeed`` is removed.
    
  751. 
    
  752. * The ``app_name`` argument to ``include()`` is removed.
    
  753. 
    
  754. * Support for passing a 3-tuple (including ``admin.site.urls``) as the first
    
  755.   argument to ``include()`` is removed.
    
  756. 
    
  757. * Support for setting a URL instance namespace without an application namespace
    
  758.   is removed.
    
  759. 
    
  760. * ``Field._get_val_from_obj()`` is removed.
    
  761. 
    
  762. * ``django.template.loaders.eggs.Loader`` is removed.
    
  763. 
    
  764. * The ``current_app`` parameter to the ``contrib.auth`` function-based views is
    
  765.   removed.
    
  766. 
    
  767. * The ``callable_obj`` keyword argument to
    
  768.   ``SimpleTestCase.assertRaisesMessage()`` is removed.
    
  769. 
    
  770. * Support for the ``allow_tags`` attribute on ``ModelAdmin`` methods is
    
  771.   removed.
    
  772. 
    
  773. * The ``enclosure`` keyword argument to ``SyndicationFeed.add_item()`` is
    
  774.   removed.
    
  775. 
    
  776. * The ``django.template.loader.LoaderOrigin`` and
    
  777.   ``django.template.base.StringOrigin`` aliases for
    
  778.   ``django.template.base.Origin`` are removed.
    
  779. 
    
  780. See :ref:`deprecated-features-1.10` for details on these changes.
    
  781. 
    
  782. * The ``makemigrations --exit`` option is removed.
    
  783. 
    
  784. * Support for direct assignment to a reverse foreign key or many-to-many
    
  785.   relation is removed.
    
  786. 
    
  787. * The ``get_srid()`` and ``set_srid()`` methods of
    
  788.   ``django.contrib.gis.geos.GEOSGeometry`` are removed.
    
  789. 
    
  790. * The ``get_x()``, ``set_x()``, ``get_y()``, ``set_y()``, ``get_z()``, and
    
  791.   ``set_z()`` methods of ``django.contrib.gis.geos.Point`` are removed.
    
  792. 
    
  793. * The ``get_coords()`` and ``set_coords()`` methods of
    
  794.   ``django.contrib.gis.geos.Point`` are removed.
    
  795. 
    
  796. * The ``cascaded_union`` property of ``django.contrib.gis.geos.MultiPolygon``
    
  797.   is removed.
    
  798. 
    
  799. * ``django.utils.functional.allow_lazy()`` is removed.
    
  800. 
    
  801. * The ``shell --plain`` option is removed.
    
  802. 
    
  803. * The ``django.core.urlresolvers`` module is removed in favor of its new
    
  804.   location, ``django.urls``.
    
  805. 
    
  806. * ``CommaSeparatedIntegerField`` is removed, except for support in historical
    
  807.   migrations.
    
  808. 
    
  809. * The template ``Context.has_key()`` method is removed.
    
  810. 
    
  811. * Support for the ``django.core.files.storage.Storage.accessed_time()``,
    
  812.   ``created_time()``, and ``modified_time()`` methods is removed.
    
  813. 
    
  814. * Support for query lookups using the model name when
    
  815.   ``Meta.default_related_name`` is set is removed.
    
  816. 
    
  817. * The MySQL ``__search`` lookup is removed.
    
  818. 
    
  819. * The shim for supporting custom related manager classes without a
    
  820.   ``_apply_rel_filters()`` method is removed.
    
  821. 
    
  822. * Using ``User.is_authenticated()`` and ``User.is_anonymous()`` as methods
    
  823.   rather than properties is no longer supported.
    
  824. 
    
  825. * The ``Model._meta.virtual_fields`` attribute is removed.
    
  826. 
    
  827. * The keyword arguments ``virtual_only`` in ``Field.contribute_to_class()`` and
    
  828.   ``virtual`` in ``Model._meta.add_field()`` are removed.
    
  829. 
    
  830. * The ``javascript_catalog()`` and ``json_catalog()`` views are removed.
    
  831. 
    
  832. * ``django.contrib.gis.utils.precision_wkt()`` is removed.
    
  833. 
    
  834. * In multi-table inheritance, implicit promotion of a ``OneToOneField`` to a
    
  835.   ``parent_link`` is removed.
    
  836. 
    
  837. * Support for ``Widget._format_value()`` is removed.
    
  838. 
    
  839. * ``FileField`` methods ``get_directory_name()`` and ``get_filename()`` are
    
  840.   removed.
    
  841. 
    
  842. * The ``mark_for_escaping()`` function and the classes it uses: ``EscapeData``,
    
  843.   ``EscapeBytes``, ``EscapeText``, ``EscapeString``, and ``EscapeUnicode`` are
    
  844.   removed.
    
  845. 
    
  846. * The ``escape`` filter now uses ``django.utils.html.conditional_escape()``.
    
  847. 
    
  848. * ``Manager.use_for_related_fields`` is removed.
    
  849. 
    
  850. * Model ``Manager`` inheritance follows MRO inheritance rules. The requirement
    
  851.   to use ``Meta.manager_inheritance_from_future`` to opt-in to the behavior is
    
  852.   removed.
    
  853. 
    
  854. * Support for old-style middleware using ``settings.MIDDLEWARE_CLASSES`` is
    
  855.   removed.