{{{
$ 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.
* owner: nobody => Hiroki Sawano
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:1>
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:2>
* needs_tests: 1 => 0
* easy: 1 => 0
Comment:
Duplicate of #29470.
--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:3>
* status: assigned => closed
* resolution: => duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:4>
Comment (by Hiroki Sawano):
Replying to [comment:4 Mariusz Felisiak]:
Oh sorry. I couldn't find the duplicated issue. Thank for checking.
--
Ticket URL: <https://code.djangoproject.com/ticket/33101#comment:5>