diff options
| author | Akshesh <aksheshdoshi@gmail.com> | 2016-06-20 21:20:05 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-05 18:12:51 -0400 |
| commit | 6a8372e6ec42eb50e05f9dbcb26b783237bdc233 (patch) | |
| tree | b0ea6c93f189009bf54bead1a7d665c27f3c6744 /docs | |
| parent | d117567c7d65c3c28858c4dfc771483b182075e4 (diff) | |
Fixed #26808 -- Added Meta.indexes for class-based indexes.
* Added the index name to its deconstruction.
* Added indexes to sqlite3.schema._remake_table() so that indexes
aren't dropped when _remake_table() is called.
Thanks timgraham & MarkusH for review and advice.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/migration-operations.txt | 16 | ||||
| -rw-r--r-- | docs/ref/models/indexes.txt | 12 | ||||
| -rw-r--r-- | docs/ref/models/options.txt | 22 |
3 files changed, 26 insertions, 24 deletions
diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt index 2de2d1a144..739b2bcdf8 100644 --- a/docs/ref/migration-operations.txt +++ b/docs/ref/migration-operations.txt @@ -202,22 +202,6 @@ is set, its column name). 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, you must assign a -``name`` to the ``index`` as done above. - ``RemoveIndex`` --------------- diff --git a/docs/ref/models/indexes.txt b/docs/ref/models/indexes.txt index c3c8d1b6eb..b63e86517c 100644 --- a/docs/ref/models/indexes.txt +++ b/docs/ref/models/indexes.txt @@ -8,8 +8,10 @@ Model index reference .. versionadded:: 1.11 -Index classes ease creating database indexes. This document explains the API -references of :class:`Index` which includes the `index options`_. +Index classes ease creating database indexes. They can be added using the +:attr:`Meta.indexes <django.db.models.Options.indexes>` option. This document +explains the API references of :class:`Index` which includes the `index +options`_. .. admonition:: Referencing built-in indexes @@ -40,9 +42,3 @@ A list of the name of the fields on which the index is desired. 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. diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt index 6569c774e8..5d385adf24 100644 --- a/docs/ref/models/options.txt +++ b/docs/ref/models/options.txt @@ -390,6 +390,28 @@ Django quotes column and table names behind the scenes. See :meth:`django.db.models.Model.save()` for more about the old and new saving algorithm. +``indexes`` +----------- + +.. attribute:: Options.indexes + + .. versionadded:: 1.11 + + A list of :doc:`indexes </ref/models/indexes>` that you want to define on + the model:: + + from django.db import models + + class Customer(models.Model): + first_name = models.CharField(max_length=100) + last_name = models.CharField(max_length=100) + + class Meta: + indexes = [ + models.Index(fields=['last_name', 'first_name']), + models.Index(fields=['first_name'], name='first_name_idx'), + ] + ``unique_together`` ------------------- |
