The non-interactive questioner doesn't tell anything about a suppressed prompt, so it is difficult to see what happened when, for example, adding a non-nullable field to a model without specifying a default.
I'd like it to print messages as shown below, like the interactive questioner does.
$ python manage.py makemigrations --noinput
It is impossible to add a non-nullable field '...' to ... without specifying a default. This is because the database needs something to populate existing rows.
If that makes sense, I'll change ask_not_null_addition
, ask_not_null_alteration
, and ask_auto_now_add_addition
in django.db.migrations.questioner.NonInteractiveMigrationQuestioner
like this:
class NonInteractiveMigrationQuestioner(MigrationQuestioner):
def ask_not_null_addition(self, field_name, model_name):
# We can't ask the user, so act like the user aborted.
print(
f"It is impossible to add a non-nullable field '{field_name}' "
f"to {model_name} without specifying a default. This is "
f"because the database needs something to populate existing "
f"rows."
)
sys.exit(3)
def ask_not_null_alteration(self, field_name, model_name):
# We can't ask the user, so set as not provided.
print(
f"It is impossible to change a nullable field '{field_name}' "
f"on {model_name} to non-nullable without providing a "
f"default. This is because the database needs something to "
f"populate existing rows.\n"
f"Existing rows that contain NULL values "
f"will have to be handled manually, for example with a "
f"RunPython or RunSQL operation."
)
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.
print(
f"It is impossible to add the field '{field_name}' with "
f"'auto_now_add=True' to {model_name} without providing a "
f"default. This is because the database needs something to "
f"populate existing rows."
)
sys.exit(3)
Duplicate of #29470.