# Changing data type of parent primary key

**URL:** <https://forums.percona.com/t/changing-data-type-of-parent-primary-key/7286>\
**Category:** Percona Toolkit\
**Created:** [November 6, 2019, 6:12pm UTC](https://forums.percona.com/t/changing-data-type-of-parent-primary-key/7286 "2019-11-06T18:12:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samgreenline](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@samgreenline](https://forums.percona.com/u/samgreenline)\
**Post date:** [November 6, 2019, 6:12pm UTC](https://forums.percona.com/t/changing-data-type-of-parent-primary-key/7286/1 "2019-11-06T18:12:57Z")

</div>

I need to convert my auto-increment PK data type from mediumInt(9) to int(11) as we’re running out of records. This key is the parent for other foreign keys.  
As far as I know, this isn’t possible with pt-online-schema-change as when the id data type is changed on the server, and the foreign key attempts to be added back for the child row, it still has the type set to mediumInt(9). All whilst data is coming in

What’s the best way I should manage this migration? Currently seems my only option to get this to work would be:

- Manually drop foreign key constraint on the child table
- Manually update the type for the child table
- Run pt-online-shema-change for updating the parent PK from mediumInt(9) to int(11)
- Once this is completed, go and add the foreign key constraint back in

This seems like a normal use case but I couldn’t find any method where PT helps with this conversion. Am I using it incorrectly? Should I be using pt-online-schema to do this? Should I be using it for more of the steps?

Should I be creating a new key on the parent, then point the child to this new key then drop the previous key?

MySQL 5.6

---

<div class="post-metadata">

**Author:** ![carlos.salguero](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/carlos.salguero/32/20_2.png) [@carlos.salguero](https://forums.percona.com/u/carlos.salguero)\
**Post date:** [November 7, 2019, 6:18am UTC](https://forums.percona.com/t/changing-data-type-of-parent-primary-key/7286/2 "2019-11-07T06:18:36Z")

</div>

Could you specify your MySQL version?

---

<div class="post-metadata">

**Author:** ![samgreenline](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@samgreenline](https://forums.percona.com/u/samgreenline)\
**Post date:** [November 7, 2019, 12:36pm UTC](https://forums.percona.com/t/changing-data-type-of-parent-primary-key/7286/3 "2019-11-07T12:36:56Z")

</div>

> [@carlos.salguero;54880](#):
>
> Could you specify your MySQL version?

Apologies, it’s MySQL 5.6, InnoDB

---

<div class="post-metadata">

**Author:** ![samgreenline](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@samgreenline](https://forums.percona.com/u/samgreenline)\
**Post date:** [November 8, 2019, 11:50am UTC](https://forums.percona.com/t/changing-data-type-of-parent-primary-key/7286/4 "2019-11-08T11:50:15Z")

</div>

Does anyone have guidance on this? I’ve looked all over for understanding the best way of doing this and making use of pt-online-schema-change but it doesn’t mention this case anywhere? I think if we can answer it, we could put this use case into documentation

---

<div class="post-metadata">

**Author:** ![samgreenline](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@samgreenline](https://forums.percona.com/u/samgreenline)\
**Post date:** [November 13, 2019, 7:51pm UTC](https://forums.percona.com/t/changing-data-type-of-parent-primary-key/7286/5 "2019-11-13T19:51:04Z")

</div>

Anybody have an idea on this?
