From eacd4977f6a4bb038e82796ba79a2f61bae330c6 Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Mon, 2 May 2022 17:22:54 +0200 Subject: Refs #27064 -- Added RenameIndex migration operation. --- docs/ref/migration-operations.txt | 16 ++++++++++++++++ docs/ref/schema-editor.txt | 9 +++++++++ docs/releases/4.1.txt | 5 ++++- 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt index 0f50c1eb8e..f8bfc4fb6b 100644 --- a/docs/ref/migration-operations.txt +++ b/docs/ref/migration-operations.txt @@ -222,6 +222,22 @@ Creates an index in the database table for the model with ``model_name``. Removes the index named ``name`` from the model with ``model_name``. +``RenameIndex`` +--------------- + +.. versionadded:: 4.1 + +.. class:: RenameIndex(model_name, new_name, old_name=None, old_fields=None) + +Renames an index in the database table for the model with ``model_name``. +Exactly one of ``old_name`` and ``old_fields`` can be provided. ``old_fields`` +is an iterable of the strings, often corresponding to fields of +:attr:`~django.db.models.Options.index_together`. + +On databases that don't support an index renaming statement (SQLite and MariaDB +< 10.5.2), the operation will drop and recreate the index, which can be +expensive. + ``AddConstraint`` ----------------- diff --git a/docs/ref/schema-editor.txt b/docs/ref/schema-editor.txt index 719e69826f..99d93f5ab4 100644 --- a/docs/ref/schema-editor.txt +++ b/docs/ref/schema-editor.txt @@ -79,6 +79,15 @@ Adds ``index`` to ``model``’s table. Removes ``index`` from ``model``’s table. +``rename_index()`` +------------------ + +.. versionadded:: 4.1 + +.. method:: BaseDatabaseSchemaEditor.rename_index(model, old_index, new_index) + +Renames ``old_index`` from ``model``’s table to ``new_index``. + ``add_constraint()`` -------------------- diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index 677e8c0345..38dcdb94e0 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -342,7 +342,10 @@ Management Commands Migrations ~~~~~~~~~~ -* ... +* The new :class:`~django.db.migrations.operations.RenameIndex` operation + allows renaming indexes defined in the + :attr:`Meta.indexes ` or + :attr:`~django.db.models.Options.index_together` options. Models ~~~~~~ -- cgit v1.3