How to alter an existing table in MySQL, setting foreign key to another table, using the command line?
You have to drop existing foreign key
and create another one. For example like this:
ALTER TABLE my_table DROP FOREIGN KEY my_key;
ALTER TABLE my_table ADD CONSTRAINT my_key FOREIGN KEY ('some_id')
REFERENCES some_new_table ('some_other_id') ON UPDATE CASCADE ON DELETE CASCADE;