﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31444	ForeignKey migrations without database changes shouldn't touch the database	Peter Law	nobody	"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."	Bug	closed	Migrations	2.2	Normal	needsinfo			Unreviewed	0	0	0	0	0	0
