I've generally carried a second key with me as backup just in case. Another habit I got into was ALWAYS locking from outside with the key. That way, if the car is locked, I have the key with me. (Some cars even require that the driver's door be locked from the outside with the key.)
Another solution that has worked well is driving cars that are so old, so depreciated out, that there really is no need to lock anything. On this theme, I had a teacher in junior high who owned a rusted Ford Pinto. He hated the car. One night (or so he claimed), he tried to get someone to steal it by leaving it in the Safeway parking lot with the engine running. Half an hour later or whatever, he came out to find...it was still there.