#30108: Include FK constraints when adding columns in PostgreSQL
--------------------------------------+------------------------------------
Reporter: Dan Tao | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):
* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
Comment:
First, thanks for the very detailed report and the patch.
For posterity here are similar comments to the ones I left on your Github
PR.
> Somewhat surprisingly, this attribute is only defined on the sqlite3
backend. (Why there was any need to optimize this particular backend, I
couldn't say.)
That's because SQLite doesn't support `ALTER TABLE ADD CONSTRAINT`; the
table has to be rebuilt on column addition so the only way to define
foreign constraints is by inlining them.
> I'm not sure what the solution is. Perhaps the code could be refactored
so that the postgresql backend only applies the sql_create_inline_fk
optimization in add_field (which is when this scenario can occur) and not
in create_model (when it shouldn't matter, because a table scan on an
empty table is not problematic).
I think it should be done for all backends that support it on field
addition. As you've said it's not ''that'' useful in table creation cases
anyway because the table will be empty so the operation will be really
fast. That would also be really hard to support for circular `CreateModel`
across apps. To summarize I think it's a great addition for `AddField`
(and probably `AlterField`?) but it's likely not worth the complexity it
would incur for `CreateModel`.
I left a few comments on your PR for improvements, mainly around adding
support for MySQL and Oracle as well. Please uncheck ''patch needs
improvement'' once you've addressed them so the patch appears in the
review queue.
--
Ticket URL: <https://code.djangoproject.com/ticket/30108#comment:3>
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/062.95c9e7ebe0e1b960f6d19b6f689e46b9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.