Skip to main content

Command

This class provides a management command to create the database tables required for a SQL cache backend. It can automatically identify cache tables from project settings or accept specific table names as arguments. The class supports targeting specific databases and includes a dry-run mode to preview the generated SQL without executing it.

Attributes

AttributeTypeDescription
helpstring = "Creates the tables needed to use the SQL cache backend."Creates the tables needed to use the SQL cache backend.
requires_system_checkslist = []A list of system checks that must be performed before the command is executed, which is empty for this command.

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 table names, database selection, and dry-run mode.

Parameters

NameTypeDescription
parser[CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser)The argument parser instance to which the cache table configuration arguments will be added.

handle()

@classmethod
def handle(
*tablenames: string,
**options: dict
)

Executes the command logic to identify and create cache tables based on provided arguments or the project's cache settings.

Parameters

NameTypeDescription
*tablenamesstringOptional positional arguments specifying specific table names to create.
**optionsdictA dictionary of command options including 'database', 'dry_run', and 'verbosity'.

create_table()

@classmethod
def create_table(
database: string,
tablename: string,
dry_run: boolean
)

Generates and executes the SQL required to create a specific cache table and its associated indexes on the target database.

Parameters

NameTypeDescription
databasestringThe alias of the database connection where the table should be created.
tablenamestringThe name of the database table to be created for the cache backend.
dry_runbooleanIf true, the method prints the SQL statements to stdout instead of executing them against the database.