Best practices to fix a threaded nut inside a print
One good option would be to - if possible - change the design, so the nut is inserted from the opposite side, so that the bolt just pulls it in tighter rather than pulling it out.

Another option would be to instead of using a nut, use a brass threaded insert. These are like nuts, except they have ridges that are specifically aimed at locking it inside the plastic.