Prepositions in English are very idiomatic, so when referring to farms, the preposition we use in English is usually on and is never in. However, when referring to cities and towns, the preposition is usually in. In most cases, in a farm doesn't exist as it sounds very unnatural.
Here are a few examples of on a farm:
Ex: I have several cows on my farm.
Ex: They live together on a farm.