MySQL constraints preventing import of single table

One of those doh!! moments when you do something quickly to get it working and didn’t think through the consequences.

I had 3 linked tables in a database that had constraints on them. I had forgotten I had put these constraints in there (3 years have passed since I did this work).

I truncated one of the tables to re-import from the dev system with some added fields. Unfortunately the constraint wiped the 3rd table.
I couldn’t re-import from the backup to the accidentally deleted table due to constraint errors.

A quick and hacky fix was required;


Do the import, then.


This was on an old project, On new projects I use migrations so this would have been avoided.

My recommendation is that if you aren’t already using the migrations feature in your php framework to start using them immediately to avoid headaches in the future when going from your development environment to your staging environment.

Be the first to comment

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.