It's generally safe for a child to fly if the earache is not caused by infection. If the cause of an earache is an infection, it is safe not to fly as the pressure changes might exert additional pressure, which can worsen the pain.  Over-the-counter medications can manage earache without infection during a flight and is safe.