Attaching a Spur Gear onto a Motor

Grind a flat spot, use a gear with set screw, there are different types of loctite you can use.

https://www.google.com/search?q=loctite&rlz=1C9BKJA_enCA832CA832&hl=en-US&prmd=sivn&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjigMXTmbPmAhXKvp4KHVxIACEQ_AUoAnoECBAQAg&biw=1024&bih=659