Record deletion bug fix

A bug appeared after moving to MySQL.
MySQL requires deleting "child" records before "parent", sqlite3 didn't
care.