Author Topic: MySQL Gotcha (well, got me rather)  (Read 2342 times)

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
MySQL Gotcha (well, got me rather)
« on: July 22, 2008, 03:56:50 PM »
So we're bringing on a new customer this week and they started testing out our app today. My boss ran an export just to make sure things looked right and noticed some weird values showing up.
I was a little bit stumped at first glance so I grabbed a backup and started to check some things out. Sure enough, we had bad data that I couldn't immediately explain. Then it hit me. I truncated some tables this morning so they wouldn't have a bunch of test data and forgot about the new custom field value table we put in for this release. We also upgraded our MySQL version for this release and apparently since I didn't have any foreign keys defined on the table (shame on me) instead of delete the rows like in the old MySQL version, it does a quick truncate by dropping the table and recreating it, thus resetting the auto increment counter back to 1. So the new records, instead of starting off where they left off like I expected, started at 1 and overlapped with the custom values table giving us some odd data.
I should've just recreated the database from scratch instead of being lazy, and I'll probably end up adding the foreign keys now too. Thankfully, they're just testing.
This signature intentionally left blank.