Skip to main content

AddIndexConcurrently

Create an index using PostgreSQL's CREATE INDEX CONCURRENTLY syntax.

Attributes

AttributeTypeDescription
atomicboolean = FalseIndicates that this operation cannot run inside a transaction block, as required by PostgreSQL for concurrent index creation.
category[OperationCategory](../../../db/migrations/operations/base/operationcategory.md?sid=django_db_migrations_operations_base_operationcategory) = OperationCategory.ADDITIONClassification of the migration operation used to identify it as an addition of a database schema element.

Constructor

Signature

def AddIndexConcurrently(
model_name: str,
index: [Index](../../../db/models/indexes/index.md?sid=django_db_models_indexes_index)
) - > null

Parameters

NameTypeDescription
model_namestrThe name of the model the index is for.
index[Index](../../../db/models/indexes/index.md?sid=django_db_models_indexes_index)The index object to be created concurrently.

Methods


describe()

@classmethod
def describe() - > string

Returns a human-readable string describing the index creation operation, including the index name, fields, and target model.

Returns

TypeDescription
stringA formatted string detailing the concurrent index creation for migration logs.

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)
) - > null

Performs the forward migration by creating the index concurrently on the database. This method ensures the operation is not wrapped in a transaction to satisfy PostgreSQL requirements.

Parameters

NameTypeDescription
app_labelstringThe label of the 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 SQL statements.
from_state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The state of the project before the migration is applied.
to_state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The state of the project after the migration is applied, used to retrieve the model definition.

Returns

TypeDescription
null

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)
) - > null

Performs the reverse migration by removing the index concurrently from the database. This method ensures the operation is not wrapped in a transaction to satisfy PostgreSQL requirements.

Parameters

NameTypeDescription
app_labelstringThe label of the 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 SQL statements.
from_state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The state of the project before the migration is reversed, used to retrieve the model definition.
to_state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The state of the project after the migration is reversed.

Returns

TypeDescription
null