#34417: AlterField migration on ForeignKey field re-creates foreign key 
constraints
unnecessarily
--------------------------------------+------------------------------------
     Reporter:  Ömer Faruk Abacı      |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Migrations            |                  Version:  4.1
     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
--------------------------------------+------------------------------------
Changes (by Simon Charette):

 * stage:  Unreviewed => Accepted


Comment:

 Dropping the foreign key and recreating it [https://dbfiddle.uk/hgRUL6q6
 is effectively not necessary on PostgreSQL] but
 [https://dbfiddle.uk/OJ6KqwrW it is on MySQL] as this backend requires an
 index on the ''referencing'' side of the relation and will silently
 default to using an existing one if its present (see #31335 for more
 details).

 Given the contention issues associated with dropping a foreign key on
 PostgreSQL I think it's a worthy investment to try to make things better
 on databases that are not affected by this quirk.

 Would you like
 [https://docs.djangoproject.com/en/4.1/internals/contributing/writing-code
 /submitting-patches/ to work on a patch]? The
 
[https://github.com/django/django/blob/d2b688b966f5d30414899549412d370e1317ddb8/django/db/backends/base/schema.py#L852-L1198
 alter_field method is where you want to start looking] and you'll likely
 need a feature flag to denote that foreign keys must be dropped or not
 based on the backend.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34417#comment:1>
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/01070186ebe77d9a-a3a383db-6999-46b1-854d-b1c9031be390-000000%40eu-central-1.amazonses.com.

Reply via email to