#31444: ForeignKey migrations without database changes shouldn't touch the
database
--------------------------------------+------------------------
Reporter: Peter Law | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
If you have a model like this:
{{{#!python
class Thing(models.Model):
user = models.ForeignKey('auth.User', related_name='+')
}}}
And you then decide to change the related name, like so:
{{{#!python
class Thing(models.Model):
user = models.ForeignKey('auth.User', related_name='things')
}}}
Then Django will create a migration for this change. I understand why the
migration is present (all fine so far).
At least for Postgres (I've not tested elsewhere), when Django runs the
migration it will end up dropping and re-adding the foreign key (which
involves locking the table and having the database revalidate the
ForeignKey) but nothing else.
In a production system this is at best inconvenient and at worst can
significantly impact site performance for the duration of the migration
(or force you to take the site offline to run the migration).
Ideally Django would detect that nothing needs to be done to the database
for this migration and not emit any SQL for this migration.
There might be a general question here about why the foreign key is being
dropped and re-created (and if we can avoid that, that would be even
better), though I'd be happy for now with a fix just for the case of a no-
op.
--
Ticket URL: <https://code.djangoproject.com/ticket/31444>
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/053.3863576d641cab3a41b1846a4a64559a%40djangoproject.com.