Fix: WordPress Media Library and Attachments Broken After Moving/Cloning Site

I’ve spent countless hours on this problem after it’s happened to three of my clients.  Turns out what has been going wrong, isn’t simply an Automatic Post Thumbnails or Auto Featured Image Plugin, and it’s mostly not simply a difference in Server Configuration (PHP version or whatever)…

For years now, I have made it a point to change my clients’ table prefix from wp_ to something more unique for security purposes, and because it allows me to use the same database which simplifies the process of switching between to versions of a WordPress installation.

I’d duplicate the current site to a subdirectory like /staging/, or whatever, download the database, open the database in a programming text editor, do a find and replace for the domain, replacing all instances so they include the extra directory, then, because it was the perfect opportunity to do so, I’d also do a find and replace to turn all intances of wp_ with xyzabc_ then save the file and import it into the existing database and switch the wp-config.php file in the subdirectory version of the site to use the new xyxabc_ table prefix.

Now I’d have a nice sandbox environment to test out upgrades to the site or any major changes.  Not anymore.  You can no longer simply find-and-replace the table prefix in the database.  I’ve noticed this as of WordPress 3.4.1.  In the past I have only had this problems with sites running Woo themes.