﻿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
28639	Changing a primary key doesn't change corresponding foreign keys	Chen Chun-Chia	nobody	"== Problem Description

    Changes of primary key do not apply to all relative models when applying multiple migrations.


== Django Version

    Both 1.11.1 and 1.11.5 are tested


== Reproduce Steps

1. Initial model
{{{
class Pub(models.Model):
    code = models.CharField(max_length=4, primary_key=True)


class Staff(models.Model):
    pub = models.ForeignKey('Pub')


class Album(models.Model):
    pub = models.ForeignKey('Pub')


class Music(models.Model):
    album = models.ForeignKey('Album')
    name = models.CharField(max_length=32)
}}}

2. Make migrations --> `0001_initial.py`


3. Alter max_length of Music.name to 64 --> `0002_alter_music_name.py`

4. Alter max_length of Pub.code to 8 --> `0003_alter_pub_code.py`

5. Final model
{{{
class Pub(models.Model):
    code = models.CharField(max_length=16, primary_key=True)  # 0003_alter_pub_code.py


class Staff(models.Model):
    pub = models.ForeignKey('Pub')


class Album(models.Model):
    pub = models.ForeignKey('Pub')


class Music(models.Model):
    album = models.ForeignKey('Album')
    name = models.CharField(max_length=64)  # 0002_alter_music_name.py
}}}

6. Use clean database (drop and recreate database)

7. Run migrate

8. Result
{{{
Length of Pub.code : 8
Length of Staff.pub_id : 4  ### wrong
Length of Album.pub_id : 8
}}}


== Observation

    After applying `0002_alter_music_name.py`, only `Album` exists in `Pub._meta.related_objects of state.apps`, but `Staff` is gone.
"	Bug	closed	Migrations	1.11	Normal	duplicate			Unreviewed	0	0	0	0	0	0
