The box has to be rated to carry a fan
This is the single most important thing on this page. A ceiling fan is heavier than a light fitting and it moves continuously while suspended, so it needs an outlet box specifically listed for fan support, secured to structure rather than to drywall. An ordinary lighting box is not rated for that, and a fan hung from one works itself loose over months or years — the failure is gradual, then sudden. Where an existing box is not fan-rated, replacing it is part of the job, and roughly what turns a short visit into a longer one.