Command
This class provides a management command that removes all data from a specified database, including data added during migrations. It supports interactive confirmation, sequence resetting, and the ability to emit post-migration signals to restore applications to a clean state. Users can specify the target database and control whether the command prompts for input during execution.
Attributes
| Attribute | Type | Description |
|---|---|---|
| help | string = Removes ALL DATA from the database, including data added during migrations. Does not achieve a "fresh install" state. | Removes ALL DATA from the database, including data added during migrations. Does not achieve a "fresh install" state. |
| stealth_options | tuple = ("reset_sequences", "allow_cascade", "inhibit_post_migrate") | A tuple of internal-use option names that are accepted by the command but not exposed in the help output. |
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 database selection and interaction mode.
Parameters
| Name | Type | Description |
|---|---|---|
| parser | [CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser) | The argument parser instance to which flush-specific arguments like --noinput and --database will be added. |
handle()
@classmethod
def handle(
**options: dict
)
Executes the database flush logic to irreversibly remove all data from the specified database and optionally triggers post-migration signals.
Parameters
| Name | Type | Description |
|---|---|---|
| **options | dict | A dictionary of parsed command options including 'database' for the target alias, 'interactive' for user prompts, and internal stealth options. |