﻿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
32743	Migrations don't alter foreign key data types when referencing primary keys in MTI models.	Mariusz Felisiak	David Wobrock	"Migrations don't alter foreign key data types when referencing primary keys in MTI models, e.g.
- before state:
{{{
class Parent(models.Model):
    pass


class Child(Parent):
    pass


class MainModel(models.Model):
    child = models.ForeignKey(Child, models.CASCADE)
}}}
- after state:
{{{
class Parent(models.Model):
    id = models.BigAutoField(primary_key=True)
}}}

`makemigrations` generates a single operation:
{{{
migrations.AlterField(
    model_name='parent',
    name='id',
    field=models.BigAutoField(primary_key=True, serialize=False),
),
}}}
which doesn't change `MainModel.child`'s datatype:
{{{
$ python manage.py sqlmigrate test_two 0002
--
-- Alter field id on parent
--
ALTER TABLE `test_two_child` DROP FOREIGN KEY `test_two_child_parent_ptr_id_537e8ba7_fk_test_two_parent_id`;
ALTER TABLE `test_two_parent` MODIFY `id` bigint AUTO_INCREMENT NOT NULL;
ALTER TABLE `test_two_child` MODIFY `parent_ptr_id` bigint NOT NULL;
ALTER TABLE `test_two_child` ADD CONSTRAINT `test_two_child_parent_ptr_id_537e8ba7_fk` FOREIGN KEY (`parent_ptr_id`) REFERENCES `test_two_parent` (`id`);
}}}

and throws an error on MySQL:
{{{
MySQLdb._exceptions.OperationalError: (3780, ""Referencing column 'child_id' and referenced column 'parent_ptr_id' in foreign key constraint 'test_two_mainmodel_child_id_3ca4683f_fk_test_two_' are incompatible."")
}}}

I couldn't find an existing ticket.

Noticed when checking #32742. "	Bug	closed	Migrations	3.2	Normal	fixed		David Wobrock	Ready for checkin	1	0	0	0	0	0
