Command
This class squashes an existing set of migrations, from a specified start point until a target migration, into a single new migration file. It provides functionality to optimize the resulting operations, handle dependencies, and generate the new migration script while maintaining a record of the replaced migrations. The class also supports interactive user confirmation and custom naming for the squashed output.
Attributes
| Attribute | Type | Description |
|---|---|---|
| help | string | Squashes an existing set of migrations (from first until specified) into a single new one. |
Methods
add_arguments()
@classmethod
def add_arguments(
parser: [CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser)
)
Configures the command line argument parser with options for selecting the app, migration range, and output formatting.
Parameters
| Name | Type | Description |
|---|---|---|
| parser | [CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser) | The argument parser instance to which the squashmigration arguments will be added. |
handle()
@classmethod
def handle(
**options: dict
) - > null
Executes the squashing logic by consolidating operations from a range of migrations into a single new migration file. This method validates the app and migrations, optionally optimizes operations, and writes the resulting migration to disk.
Parameters
| Name | Type | Description |
|---|---|---|
| **options | dict | A dictionary of parsed command line arguments including 'app_label', 'migration_name', and 'no_optimize'. |
Returns
| Type | Description |
|---|---|
null | Returns null; output is written to the filesystem and stdout. |
find_migration()
@classmethod
def find_migration(
loader: [MigrationLoader](../../../../db/migrations/loader/migrationloader.md?sid=django_db_migrations_loader_migrationloader),
app_label: str,
name: str
) - > [Migration](../../../../db/migrations/migration/migration.md?sid=django_db_migrations_migration_migration)
Retrieves a specific migration object from the loader based on a partial or full name prefix. Raises a CommandError if the name is ambiguous or if no matching migration is found for the specified app.
Parameters
| Name | Type | Description |
|---|---|---|
| loader | [MigrationLoader](../../../../db/migrations/loader/migrationloader.md?sid=django_db_migrations_loader_migrationloader) | The migration loader instance containing the current migration graph. |
| app_label | str | The name of the Django application the migration belongs to. |
| name | str | The name or prefix of the migration to locate. |
Returns
| Type | Description |
|---|---|
[Migration](../../../../db/migrations/migration/migration.md?sid=django_db_migrations_migration_migration) | The migration instance matching the provided app label and name prefix. |