summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2021-08-06 09:17:13 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-10-12 15:19:39 +0200
commit32f1fe5f89bc9ae98161c07f3676f6aaedc8e877 (patch)
treecea3542a8fac71cd0e3a2c43e01b0c42362a7e39 /django/db
parent241ba23870221085cc31ae302b9647f375f9c6c6 (diff)
Fixed #29470 -- Logged makemigrations automatic decisions in non-interactive mode.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/migrations/questioner.py32
1 files changed, 32 insertions, 0 deletions
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)