Skip to main content

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

AttributeTypeDescription
helpstring = 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_optionstuple = ("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

NameTypeDescription
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

NameTypeDescription
**optionsdictA dictionary of parsed command options including 'database' for the target alias, 'interactive' for user prompts, and internal stealth options.