#23581: Migration shouldn't generate "DROP DEFAULT" SQL if no database changes
are
required
--------------------------------------+------------------------------------
Reporter: john_scott | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by shaib):
I just took a short look, and, TBH, I don't quite understand why we're
setting and removing defaults around line 545. I see reason to use
defaults in the database only when adding new columns; while adding
columns can be the result of `alter_field` (e.g. when changing a M2M to a
FK), I think this is not the case being handled here.
The test for `new_field.default is not None` looks like a bug -- the
intention was probably to use `self.effective_default(new_field) is not
None`.
The comments in #23043 are that no default should be ''left'' in the
database; setting defaults is unavoidable when adding new columns to
existing tables. That is also why `add_field` drops the defaults it adds.
In a Django app, defaults are handled in Python, not SQL; if the code
tries to insert rows in a way that relies on database defaults, it is most
probably a bug -- so it is better to error out.
--
Ticket URL: <https://code.djangoproject.com/ticket/23581#comment:18>
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/068.9654e7bc4775e67996857dad50c367d9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.