Skip to main content

CollationOperation

This class represents a database operation for managing custom collations within a schema. It provides functionality to create and remove collations with specific locales, providers, and determinism settings. The class integrates with a schema editor to execute the necessary SQL commands and supports state tracking for migrations.

Attributes

AttributeTypeDescription
namestringThe unique identifier for the collation being created or managed within the database schema.
localestringThe locale identifier that defines the language and region rules for string comparison and sorting.
providerstring = "libc"The library provider used for the collation, such as 'libc' or 'icu', which determines the underlying implementation.
deterministicboolean = trueA boolean flag indicating whether the collation should be deterministic, affecting how string equality is evaluated.

Constructor

Signature

def CollationOperation(
name: string,
locale: string,
provider: string = "libc",
deterministic: boolean = true
) - > null

Parameters

NameTypeDescription
namestringThe name of the collation to be created.
localestringThe locale for the collation.
providerstring = "libc"The collation provider to be used.
deterministicboolean = trueSpecifies if the collation is deterministic.

Methods


state_forwards()

@classmethod
def state_forwards(
app_label: string,
state: [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)
) - > null

Updates the project state to reflect the addition or removal of the collation during a migration.

Parameters

NameTypeDescription
app_labelstringThe label of the application the migration belongs to.
state[ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)The current state of the project to be updated.

Returns

TypeDescription
nullNothing is returned as this method modifies the state object in-place.

deconstruct()

@classmethod
def deconstruct() - > tuple

Returns a 3-tuple containing the class name, positional arguments, and keyword arguments required to reconstruct the operation.

Returns

TypeDescription
tupleA tuple of (qualname, positional_args, keyword_args) used for serializing the operation into migration files.

create_collation()

@classmethod
def create_collation(
schema_editor: [BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor)
) - > null

Executes the SQL command to create a new collation in the database using the specified locale and provider settings.

Parameters

NameTypeDescription
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 COLLATION statement.

Returns

TypeDescription
nullNothing is returned; the database schema is modified directly via the schema editor.

remove_collation()

@classmethod
def remove_collation(
schema_editor: [BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor)
) - > null

Executes the SQL command to drop the specified collation from the database.

Parameters

NameTypeDescription
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 COLLATION statement.

Returns

TypeDescription
nullNothing is returned; the database schema is modified directly via the schema editor.