Skip to main content

Command

This class provides a command-line interface to generate the SQL statements required to reset all tables in a database to their initial post-installation state. It supports targeting specific databases via an optional argument and ensures the resulting output is wrapped in a transaction. The class utilizes database-specific utilities to identify and format the necessary flush operations.

Attributes

AttributeTypeDescription
helpstringReturns a list of the SQL statements required to return all tables in the database to the state they were in just after they were installed.
output_transactionboolean = TrueA boolean flag indicating whether the command's output should be wrapped in a database transaction.

Methods


add_arguments()

@classmethod
def add_arguments(
parser: [CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser)
) - > null

Configures the command-line argument parser to include custom options for database selection.

Parameters

NameTypeDescription
parser[CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser)The argument parser instance used to define command-line flags and options.

Returns

TypeDescription
nullNothing is returned; the parser object is modified in place.

handle()

@classmethod
def handle(
**options: dict
) - > string

Generates and returns a list of SQL statements required to reset all database tables to their post-installation state.

Parameters

NameTypeDescription
**optionsdictA dictionary of command-line arguments, including the target database alias and verbosity level.

Returns

TypeDescription
stringA newline-separated string of SQL statements used to flush the database tables.