Foreign keys are causing me too many problems modifying an database structure to meet new requirements – I want to modify primary keys but it seems I can’t when foreign keys reference the table in question (I think because MySQL drops the table and re-creates).
So while I work on the DB, I’d like to simply remove all the foreign keys and re-create them later. Is there a neat way to do so?
You can simply issue the following command before any Alter Table statements you are going to make:
This will turn off foreign key constraint checks for your database connection. You can then make your changes without needing to worry about constraints.
After you are done, don’t forget to issue:
To turn them back on.
Note that this will still not allow you to create a new foreign key constraint that would fail because the column data types don’t match.