It's always one of the dumbest and worst problems when working with wheels and motors (other than finding a gearbox...maybe). It's different for every situtation. You could make it a square shaft, or drill a hole in the gear and file a flat part into the shaft and use a set screw. Depends on how much force you need to support.
What's your setup? If you have access to a mill and a lathe it makes everything much easier and more reliable...but few can do that. For the rest of us it ends up being a make-or-break decision for a design.
Hint: go with servos motors and their accessories, or go with radio-controlled truck parts.