#30390: makemigrations requires default when adding non-nullable field even when
there are no rows.
-------------------------------------+-------------------------------------
Reporter: Neil du | Owner: nobody
Toit |
Type: | Status: new
Cleanup/optimization |
Component: | Version: 2.2
Migrations | Keywords: makemigrations
Severity: Normal | default null
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
When adding a non-nullable field to a model, and then running
python manage.py makemigrations <appname>
Django will respond with the following:
"You are trying to add a non-nullable field <field> to <model> without a
default; we can't do that (the database needs something to populate
existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a
null value for this column)
2) Quit, and let me add a default in models.py
Select an option: "
This is quite frustrating when there are no existing rows. It requires
more effort and, more importantly, leads to confusion about what
migrations are doing. I frequently go back and check the database for my
own sanity after seeing this message.
Desired behavior:
If there are no rows then there is no need for a default. This message
should not be displayed and the migration should simply be run.
--
Ticket URL: <https://code.djangoproject.com/ticket/30390>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.de5bb65a144a329478b1c9421b65b497%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.