When installing a ceiling fan, the electrical box that the wires connect to must be rated for the load of the fan. If your existing electrical box isn’t rated for ceiling fans, or you can’t use it because it is fastened to the side of a joist, there are a couple of ways to solve this issue without replacing the entire fixture.
In an old-work installation, you can install a fan-rated pan box or saddle box that gets screwed to the joist from underneath. This type of box is often used in new construction, but it’s also available for remodel/rewire jobs. Alternatively, you could install a 2×6 vertically to the side of the joist, and then attach your box to that. There are also fan-rated boxes meant to go on the side of a structural member — these would work in your situation as well.
An important thing to remember about using an existing box for a fan is that the existing breaker needs to be shut off before you start work. Then, you need to probe around the existing box and make sure that it is strong enough for a ceiling fan. You can do this by trying to wiggle the box to see how easily it moves. A fan-rated box will have no play, while a non-fan rated box may have quite a bit of movement.
You may also want to consider whether the screws you use are adequate for the load of a ceiling fan. If they are too thin, the box will not be able to withstand the force of the spinning fan. Skimpy screws can actually break or shear off during operation, so you need to use appropriate, high-quality screws.