The United States Citizenship and Immigration Services (USCIS) requires for you to submit a different affidavit of support form depending on whether you have filed an immigrant visa petition or a non-immigrant visa petition.
"Immigrant and non-immigrant visa" means...
An immigrant visa is issued to persons wishing to immigrate to the U.S. to live and work permanently, sometimes referred to as a Green Card Visa. This category generally includes immediate relatives of U.S. Citizens or Permanent Residents wishing to permanently leave their foreign country and settle and live in the U.S. permanently. This generally includes family sponsorship by either a U.S. Citizen or Permanent resident for their foreign family members such as spouse, children, parents, and sibling filed through a Petition for Alien Relative USCIS Form I-130. This category also includes immigration based on a U.S. employer hiring a foreign employee or executive to immigrate to the U.S. with his/her family and permanently work in the U.S. on a Green Card Visa.
A nonimmigrant visa is the visa issued to persons wishing to temporary visit or work in the U.S. without actually abandoning their foreign residence. (i.e. tourist visitor visa, medical treatment, business, temporary work, student, or fiancée visa). Generally, this category includes temporary visitors that must leave the U.S. and return to their foreign country after a specific time period or when certain conditions are met. For example, a fiancée visa for a U.S. Citizen's fiancée in a foreign country allows the fiancée to visit the U.S. on a non-immigrant visa for a temporary amount of time in order to allow the engaged couple to get married in the U.S. Once married, then the U.S. spouse can file to change the immigrant's status to permanent resident.
Now that we know the difference between immigrant and non-immigrant based immigration we can talk about when to file I-134 affidavit of support form versus affidavit of support form I-864?
Contrary to popular misconception, almost all family alien relative petitions (form I-130) will require you to file an Affidavit of Support form I-864 at one point or another in the process. If you are filing for a non-family member or when the applicant is intending to temporary work, study, visit/vacation, get medical treatment and the likes then a form I-134 must be filed. Also note that a fiancée visa application (I-129F Petition for Alien fiancé) used to petition a U.S. Citizen's foreign fiancée (K-1) to visit the U.S. for marriage purposes to complete the processing for permanent resident status requires that the I-134 Affidavit of Support Form be filed initially and once that person is in the U.S. and has gotten married then a form I-864 Affidavit of Support form is filed during the change of status procedure.
If a U.S. Citizen or a Permanent Resident files an I-130 petition for their relative then then will be required to file an I-864 Affidavit of Support form once the case has been approved and is ready to process further. If a fiancée visa petition is filed I-129F then along with petition and I-134 Affidavit of Support form is filed. So for immigrant visa categories use I-864 for non-immigrant visa categories use I-134 at the initial stage.