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
| Attribute | Type | Description |
|---|---|---|
| name | string | The unique identifier for the collation being created or managed within the database schema. |
| locale | string | The locale identifier that defines the language and region rules for string comparison and sorting. |
| provider | string = "libc" | The library provider used for the collation, such as 'libc' or 'icu', which determines the underlying implementation. |
| deterministic | boolean = true | A 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
| Name | Type | Description |
|---|---|---|
| name | string | The name of the collation to be created. |
| locale | string | The locale for the collation. |
| provider | string = "libc" | The collation provider to be used. |
| deterministic | boolean = true | Specifies 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
| Name | Type | Description |
|---|---|---|
| app_label | string | The 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
| Type | Description |
|---|---|
null | Nothing 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
| Type | Description |
|---|---|
tuple | A 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
| Name | Type | Description |
|---|---|---|
| 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
| Type | Description |
|---|---|
null | Nothing 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
| Name | Type | Description |
|---|---|---|
| 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
| Type | Description |
|---|---|
null | Nothing is returned; the database schema is modified directly via the schema editor. |