I’ve taken over the development of a web app that uses a mysql innodb database. The client has a lot of duplicate records in the db on accident. I’m building a merge tool to keep one record and push the other’s associated data to it.
So, for example because of a typo, I might have.
entity_id entity_cat common_name
--------------------------------------
abcdefg customer John Doe
hijklmn customer Jon Doe
I then have a bunch of tables that are linked to entity_id. I want to delete ‘hijklmn’, and have all of the associated data in other tables change their ‘customer_entity_id’ to ‘abcdef’.
The problem is, the relationships all have on delete cascade. Is there any way for me to merge these two records without losing any data?
With regards to your
ON DELETE CASCADEissue, you can temporarily disable all foreign key constraints for the purpose of your query with the script template below: