# Changing datatypes of foreign keys

**URL:** <https://forums.percona.com/t/changing-datatypes-of-foreign-keys/475>\
**Category:** Other MySQL® Questions\
**Created:** [September 29, 2007, 6:51pm UTC](https://forums.percona.com/t/changing-datatypes-of-foreign-keys/475 "2007-09-29T18:51:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![omakase](https://avatars.discourse-cdn.com/v4/letter/o/e480ec/32.png) [@omakase](https://forums.percona.com/u/omakase)\
**Post date:** [September 29, 2007, 6:51pm UTC](https://forums.percona.com/t/changing-datatypes-of-foreign-keys/475/1 "2007-09-29T18:51:35Z")

</div>

I want to change the data type of all my id fields in my (InnoDB) schema from mediumints to ints. The problem is there are a lot of foreign key references and I can’t figure out a simple way to change the type other than removing all he foreign key constraints, changing the columns and adding all the foreign key constraints again.

Is there an easier way?

---

<div class="post-metadata">

**Author:** ![danciulinaru](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@danciulinaru](https://forums.percona.com/u/danciulinaru)\
**Post date:** [October 8, 2007, 4:52pm UTC](https://forums.percona.com/t/changing-datatypes-of-foreign-keys/475/2 "2007-10-08T16:52:47Z")

</div>

Step 1:  
mysql\> SET FOREIGN\_KEY\_CHECKS=0;

Step 2:  
mysql\> ALTER TABLE table\_name modify column data type;

Step3:  
mysql\> SET FOREIGN\_KEY\_CHECKS=1;

Basically, is what said, but instead of removing fk, you’re just disabling them.
