Renaming foreign-key columns in MySQL Renaming foreign-key columns in MySQL mysql mysql

Renaming foreign-key columns in MySQL


AFAIK, dropping the constraint, then rename, then add the constraint back is the only way. Backup first!


In case anyone is looking for the syntax it goes something like this:

alter table customer_account drop foreign key `FK3FEDF2CC1CD51BAF`; alter table customer_account  add constraint `FK3FEDF2CCD115CB1A` foreign key (campaign_id) REFERENCES campaign(id);


here is the SQL syntax for regular keys

ALTER TABLE `thetable`  DROP KEY `oldkey`,   ADD KEY `newkey` (`tablefield`);