#33101: Improve output of non-interactive migration questioner
------------------------------------------------+------------------------
Reporter: Hiroki Sawano | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
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)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33101>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.f233e12e763a57064659006c705f7b10%40djangoproject.com.