Skip to main content

RemoveIndexConcurrently

Remove an index using PostgreSQL's DROP INDEX CONCURRENTLY syntax.

Attributes

AttributeTypeDescription
atomicboolean = FalseIndicates that this operation cannot run inside a database transaction, which is required for PostgreSQL's concurrent index removal.
category[OperationCategory](../../../db/migrations/operations/base/operationcategory.md?sid=django_db_migrations_operations_base_operationcategory) = OperationCategory.REMOVALDefines the operation type as a removal, used by the migration framework to categorize the database change.

Methods


describe()

@classmethod
def describe() - > string

Returns a human-readable string describing the migration operation for console output.

Returns

TypeDescription
stringA formatted string stating the index name and the model from which it is being concurrently removed.

database_forwards()

@classmethod
def database_forwards(
app_label: string,
schema_editor: [BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor),
from_state: [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate),
to_state: [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)
)

Executes the forward migration by dropping the specified index using PostgreSQL's CONCURRENTLY option. This method ensures the operation is not wrapped in a transaction to satisfy database requirements.

Parameters

NameTypeDescription
app_labelstringThe label of the Django application the migration belongs to.
schema_editor[BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor)The database abstraction layer used to execute the DROP INDEX SQL command.
from_state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The state of the project before the migration is applied, used to retrieve the existing index definition.
to_state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The state of the project after the migration is applied.

database_backwards()

@classmethod
def database_backwards(
app_label: string,
schema_editor: [BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor),
from_state: [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate),
to_state: [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)
)

Reverts the migration by re-creating the index concurrently on the database table. This allows the rollback to occur without locking the table against concurrent writes.

Parameters

NameTypeDescription
app_labelstringThe label of the Django application the migration belongs to.
schema_editor[BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor)The database abstraction layer used to execute the CREATE INDEX SQL command.
from_state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The state of the project before the rollback is applied.
to_state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The state of the project to roll back to, containing the index definition to be restored.