MCPcopy
hub / github.com/django/django / handle

Method handle

django/core/management/commands/flush.py:32–91  ·  view source on GitHub ↗
(self, **options)

Source from the content-addressed store, hash-verified

30 )
31
32 def handle(self, **options):
33 database = options["database"]
34 connection = connections[database]
35 verbosity = options["verbosity"]
36 interactive = options["interactive"]
37 # The following are stealth options used by Django's internals.
38 reset_sequences = options.get("reset_sequences", True)
39 allow_cascade = options.get("allow_cascade", False)
40 inhibit_post_migrate = options.get("inhibit_post_migrate", False)
41
42 self.style = no_style()
43
44 # Import the 'management' module within each installed app, to register
45 # dispatcher events.
46 for app_config in apps.get_app_configs():
47 try:
48 import_module(".management", app_config.name)
49 except ImportError:
50 pass
51
52 sql_list = sql_flush(
53 self.style,
54 connection,
55 reset_sequences=reset_sequences,
56 allow_cascade=allow_cascade,
57 )
58
59 if interactive:
60 confirm = input("""You have requested a flush of the database.
61This will IRREVERSIBLY DESTROY all data currently in the "%s" database,
62and return each table to an empty state.
63Are you sure you want to do this?
64
65 Type 'yes' to continue, or 'no' to cancel: """ % connection.settings_dict["NAME"])
66 else:
67 confirm = "yes"
68
69 if confirm == "yes":
70 try:
71 connection.ops.execute_sql_flush(sql_list)
72 except Exception as exc:
73 raise CommandError(
74 "Database %s couldn't be flushed. Possible reasons:\n"
75 " * The database isn't running or isn't configured correctly.\n"
76 " * At least one of the expected database tables doesn't exist.\n"
77 " * The SQL was invalid.\n"
78 "Hint: Look at the output of 'django-admin sqlflush'. "
79 "That's the SQL this command wasn't able to run."
80 % (connection.settings_dict["NAME"],)
81 ) from exc
82
83 # Empty sql_list may signify an empty database and post_migrate
84 # would then crash.
85 if sql_list and not inhibit_post_migrate:
86 # Emit the post migrate signal. This allows individual
87 # applications to respond as if the database had been migrated
88 # from scratch.
89 emit_post_migrate_signal(verbosity, interactive, database)

Callers

nothing calls this directly

Calls 8

no_styleFunction · 0.90
sql_flushFunction · 0.90
CommandErrorClass · 0.90
emit_post_migrate_signalFunction · 0.90
get_app_configsMethod · 0.80
execute_sql_flushMethod · 0.80
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected