GET 24/7 LIVE HELP NOW

Announcement

Announcement Module
Collapse
No announcement yet.

Changing datatypes of foreign keys

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing datatypes of foreign keys

    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?

  • #2
    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.

    Comment

    Working...
    X