Skip to main content

CreateCollation

Create a collation.

Attributes

AttributeTypeDescription
category[OperationCategory](../../../db/migrations/operations/base/operationcategory.md?sid=django_db_migrations_operations_base_operationcategory) = OperationCategory.ADDITIONThe 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

NameTypeDescription
app_labelstringThe 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

TypeDescription
nullNothing 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

NameTypeDescription
app_labelstringThe 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

TypeDescription
nullNothing 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

TypeDescription
stringA 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

TypeDescription
stringA 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

NameTypeDescription
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_labelstringThe label of the application being migrated

Returns

TypeDescription
`listnull`