Migrations: What's the right way to rename a Foreign Key?
The 2nd method you tried is the correct order to do it in.


Call BaseMigration->dropForeignKey() ($this-&gt;dropForeignKey from within the context of a migration).
Call BaseMigration->renameColumn() ($this-&gt;renameColumn).
And add the column back with with BaseMigration->addForeignKey() ($this-&gt;addForeignKey).


If you received an error during any of those steps, it's likely because MySQL is complaining about inconsistent data among the FK endpoints or the endpoints are of different data types.



EDIT BY OP

The final version of the code looked like this:

$table = 'myplugin_mytable';
$this-&gt;dropForeignKey($table, 'oldId');
$this-&gt;renameColumn($table, 'oldId', 'newId');
$this-&gt;addForeignKey($table, 'newId', 'myplugin_related', 'id', 'CASCADE', 'CASCADE');