In an action affecting the title to real property, the plaintiff, at the time of filing the complaint or at any time afterwards, or the defendant, when he sets up an affirmative cause of action in his answer and demands substantive relief, at the time of filing his answer or at any time afterwards, if the same be intended to affect real property, may file for record with the register of deeds of each county in which the real property is situated a notice of the pendency of the action, containing the names of the parties, the object of the action, and the description of the real property in that county affected thereby; but if the action be for the foreclosure of a mortgage, or the enforcement of a mechanic's or miner's lien, no such notice need be filed, except as may be specifically provided by the statutes relating thereto.
SDCL 15-10-1