Fix for SQL exception on empty class_id relation in upgrade - refs BT#7254