diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2021-08-06 09:17:13 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-12 15:19:39 +0200 |
| commit | 32f1fe5f89bc9ae98161c07f3676f6aaedc8e877 (patch) | |
| tree | cea3542a8fac71cd0e3a2c43e01b0c42362a7e39 /django | |
| parent | 241ba23870221085cc31ae302b9647f375f9c6c6 (diff) | |
Fixed #29470 -- Logged makemigrations automatic decisions in non-interactive mode.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/commands/makemigrations.py | 7 | ||||
| -rw-r--r-- | django/db/migrations/questioner.py | 32 |
2 files changed, 38 insertions, 1 deletions
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) |
