![]() |
I want to change a bunch of fieldtypes (from smallint to mediumint).
But most of them are foreign keys, so updating them results in "Cannot change column 'X': used in a foreign key constraint 'Y'... Is there a way of doing this with a migration which doesn't involve deleting the key and adding it again? Something like: Code: SET FOREIGN_KEY_CHECKS=0; ???
Disable foreign key checks temporarily:
sql Copy code SET FOREIGN_KEY_CHECKS=0; Alter the column types as needed: sql Copy code ALTER TABLE your_table MODIFY your_column MEDIUMINT; Enable foreign key checks again: sql Copy code SET FOREIGN_KEY_CHECKS=1; By temporarily disabling foreign key checks, you can modify the column types without encountering errors related to foreign key constraints. After the alterations are complete, remember to re-enable foreign key checks to maintain data integrity. |
Welcome Guest, Not a member yet? Register Sign In |