From 32f1fe5f89bc9ae98161c07f3676f6aaedc8e877 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 6 Aug 2021 09:17:13 -0400 Subject: Fixed #29470 -- Logged makemigrations automatic decisions in non-interactive mode. --- django/core/management/commands/makemigrations.py | 7 ++++- django/db/migrations/questioner.py | 32 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'django') diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py index d8eef481bd..9077660467 100644 --- a/django/core/management/commands/makemigrations.py +++ b/django/core/management/commands/makemigrations.py @@ -146,7 +146,12 @@ class Command(BaseCommand): if self.interactive: questioner = InteractiveMigrationQuestioner(specified_apps=app_labels, dry_run=self.dry_run) else: - questioner = NonInteractiveMigrationQuestioner(specified_apps=app_labels, dry_run=self.dry_run) + questioner = NonInteractiveMigrationQuestioner( + specified_apps=app_labels, + dry_run=self.dry_run, + verbosity=self.verbosity, + log=self.log, + ) # Set up autodetector autodetector = MigrationAutodetector( loader.project_state(), diff --git a/django/db/migrations/questioner.py b/django/db/migrations/questioner.py index 9284e6be41..17883ca76c 100644 --- a/django/db/migrations/questioner.py +++ b/django/db/migrations/questioner.py @@ -258,15 +258,47 @@ class InteractiveMigrationQuestioner(MigrationQuestioner): class NonInteractiveMigrationQuestioner(MigrationQuestioner): + def __init__( + self, defaults=None, specified_apps=None, dry_run=None, verbosity=1, + log=None, + ): + self.verbosity = verbosity + self.log = log + super().__init__( + defaults=defaults, specified_apps=specified_apps, dry_run=dry_run, + ) + + def log_lack_of_migration(self, field_name, model_name, reason): + if self.verbosity > 0: + self.log( + f"Field '{field_name}' on model '{model_name}' not migrated: " + f"{reason}." + ) def ask_not_null_addition(self, field_name, model_name): # We can't ask the user, so act like the user aborted. + self.log_lack_of_migration( + field_name, + model_name, + 'it is impossible to add a non-nullable field without specifying ' + 'a default', + ) sys.exit(3) def ask_not_null_alteration(self, field_name, model_name): # We can't ask the user, so set as not provided. + self.log( + f"Field '{field_name}' on model '{model_name}' given a default of " + f"NOT PROVIDED and must be corrected." + ) return NOT_PROVIDED def ask_auto_now_add_addition(self, field_name, model_name): # We can't ask the user, so act like the user aborted. + self.log_lack_of_migration( + field_name, + model_name, + "it is impossible to add a field with 'auto_now_add=True' without " + "specifying a default", + ) sys.exit(3) -- cgit v1.3