﻿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
24447	Migrations do not add a FK constraint for an existing column	Jean-Louis Fuchs	nobody	"Pull request: https://github.com/django/django/pull/4235

Consider following model:

{{{
class ForeignKeyTest(models.Model):
    id = models.AutoField(primary_key=True)
    customer = models.IntegerField()

class Customer(models.Model):
    id = models.AutoField(primary_key=True)
}}}

Then it gets migrated to this:

{{{
class ForeignKeyTest(models.Model):
    id = models.AutoField(primary_key=True)
    customer = models.ForeignKey('Customer')

class Customer(models.Model):
    id = models.AutoField(primary_key=True)
}}}

The second migration won't create the foreign key. This does not fail with sqlite! Because these migrations are handled differently. It will fail with MySQL and probably Postgres too.

The code didn't detect this case: if old_field.rel doesn't exist alter_field() must always create the foreign key and ONLY if .rel exists it must check .db_constraint, too. Since no .rel also means there was no foreign key before."	Bug	new	Migrations	1.7	Normal			Markus Holtermann	Accepted	1	1	0	1	0	0
