Change MYSQL table column type while in relationship

415 0 0 0

Last Updated : 2024-04-27 09:54:35

Some times, You will find yourself trapped into a situation where you need to change a column datatype or length, But this column is already used in PK-FK relationship and the solution for this is disable the SET foreign_key_checks = 0; then change the datatype and then re-enable it after you finish the update.

SET foreign_key_checks = 0; //Disable it


Set the updates


SET foreign_key_checks = 1; //Re-enable it

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .