CreateCollation
Create a collation.
Attributes
| Attribute | Type | Description |
|---|---|---|
| category | [OperationCategory](../../../db/migrations/operations/base/operationcategory.md?sid=django_db_migrations_operations_base_operationcategory) = OperationCategory.ADDITION | The classification of the operation, set to ADDITION to indicate this migration step adds a new resource to the database schema. |
Methods
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
Applies the collation creation to the database if the connection is PostgreSQL and migration is allowed.
Parameters
| Name | Type | Description |
|---|---|---|
| app_label | string | The label of the application being migrated |
| schema_editor | [BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor) | The database abstraction layer used to execute 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 |
Returns
| Type | Description |
|---|---|
null | Nothing is returned; the operation modifies the database schema directly. |
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
Removes the collation from the database during a migration rollback if migration is allowed.
Parameters
| Name | Type | Description |
|---|---|---|
| app_label | string | The label of the application being migrated |
| schema_editor | [BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor) | The database abstraction layer used to execute 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 rolled back |
| to_state | [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate) | The state of the project after the migration is rolled back |
Returns
| Type | Description |
|---|---|
null | Nothing is returned; the operation modifies the database schema directly. |
describe()
@classmethod
def describe() - > string
Returns a human-readable string describing the collation creation operation for migration logs.
Returns
| Type | Description |
|---|---|
string | A formatted string containing the name of the collation being created |
migration_name_fragment()
@classmethod
def migration_name_fragment() - > string
Generates a lowercase string fragment used to name the migration file containing this operation.
Returns
| Type | Description |
|---|---|
string | A string fragment in the format 'create_collation_< name >' |
reduce()
@classmethod
def reduce(
operation: [Operation](../../../db/migrations/operations/base/operation.md?sid=django_db_migrations_operations_base_operation),
app_label: string
) - > list|null
Attempts to optimize the migration by canceling out this operation if it is followed by a RemoveCollation for the same name.
Parameters
| Name | Type | Description |
|---|---|---|
| operation | [Operation](../../../db/migrations/operations/base/operation.md?sid=django_db_migrations_operations_base_operation) | The subsequent migration operation to compare against for potential reduction |
| app_label | string | The label of the application being migrated |
Returns
| Type | Description |
|---|---|
| `list | null` |