diff options
| author | Akshesh <aksheshdoshi@gmail.com> | 2016-06-25 22:02:56 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-27 10:41:01 -0400 |
| commit | 156e2d59cf92eb252c2f6ef9bb0b65f26c707de2 (patch) | |
| tree | a385db97c67f6b8504954c3df3ac88f169d13f8c /docs | |
| parent | c962b9104a22505a7d6c57bbec9eda163f486c7d (diff) | |
Fixed #26709 -- Added class-based indexes.
Added the AddIndex and RemoveIndex operations to use them in migrations.
Thanks markush, mjtamlyn, timgraham, and charettes for review and advice.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/index.txt | 1 | ||||
| -rw-r--r-- | docs/ref/migration-operations.txt | 37 | ||||
| -rw-r--r-- | docs/ref/models/index.txt | 1 | ||||
| -rw-r--r-- | docs/ref/models/indexes.txt | 48 |
4 files changed, 87 insertions, 0 deletions
diff --git a/docs/index.txt b/docs/index.txt index 58044f574e..ab38fa02f9 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -82,6 +82,7 @@ manipulating the data of your Web application. Learn more about it below: * **Models:** :doc:`Introduction to models <topics/db/models>` | :doc:`Field types <ref/models/fields>` | + :doc:`Indexes <ref/models/indexes>` | :doc:`Meta options <ref/models/options>` | :doc:`Model class <ref/models/class>` diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt index c8668d108e..485add5bcc 100644 --- a/docs/ref/migration-operations.txt +++ b/docs/ref/migration-operations.txt @@ -192,6 +192,43 @@ field like ``models.IntegerField()`` on most databases. Changes a field's name (and, unless :attr:`~django.db.models.Field.db_column` is set, its column name). +``AddIndex`` +------------ + +.. class:: AddIndex(model_name, index) + +.. versionadded:: 1.11 + +Creates an index in the database table for the model with ``model_name``. +``index`` is an instance of the :class:`~django.db.models.Index` class. + +For example, to add an index on the ``title`` and ``author`` fields of the +``Book`` model:: + + from django.db import migrations, models + + class Migration(migrations.Migration): + operations = [ + migrations.AddIndex( + 'Book', + models.Index(fields=['title', 'author'], name='my_index_name'), + ), + ] + +If you're writing your own migration to add an index, it's recommended to pass +a ``name`` to the ``index`` as done above so that you can reference it if you +later want to remove it. Otherwise, a name will be autogenerated and you'll +have to inspect the database to find the index name if you want to remove it. + +``RemoveIndex`` +--------------- + +.. class:: RemoveIndex(model_name, name) + +.. versionadded:: 1.11 + +Removes the index named ``name`` from the model with ``model_name``. + Special Operations ================== diff --git a/docs/ref/models/index.txt b/docs/ref/models/index.txt index 103775e269..d731ee37dc 100644 --- a/docs/ref/models/index.txt +++ b/docs/ref/models/index.txt @@ -8,6 +8,7 @@ Model API reference. For introductory material, see :doc:`/topics/db/models`. :maxdepth: 1 fields + indexes meta relations class diff --git a/docs/ref/models/indexes.txt b/docs/ref/models/indexes.txt new file mode 100644 index 0000000000..c3c8d1b6eb --- /dev/null +++ b/docs/ref/models/indexes.txt @@ -0,0 +1,48 @@ +===================== +Model index reference +===================== + +.. module:: django.db.models.indexes + +.. currentmodule:: django.db.models + +.. versionadded:: 1.11 + +Index classes ease creating database indexes. This document explains the API +references of :class:`Index` which includes the `index options`_. + +.. admonition:: Referencing built-in indexes + + Indexes are defined in ``django.db.models.indexes``, but for convenience + they're imported into :mod:`django.db.models`. The standard convention is + to use ``from django.db import models`` and refer to the indexes as + ``models.<IndexClass>``. + +``Index`` options +================= + +.. class:: Index(fields=[], name=None) + + Creates an index (B-Tree) in the database. + +``fields`` +----------- + +.. attribute:: Index.fields + +A list of the name of the fields on which the index is desired. + +``name`` +-------- + +.. attribute:: Index.name + +The name of the index. If ``name`` isn't provided Django will auto-generate a +name. For compatibility with different databases, index names cannot be longer +than 30 characters and shouldn't start with a number (0-9) or underscore (_). + +.. seealso:: + + Use the :class:`~django.db.migrations.operations.AddIndex` and + :class:`~django.db.migrations.operations.RemoveIndex` operations to add + and remove indexes. |
