peewee instance matching query does not exist
<p>I have the following code where I'm querying my peewee database. I'm getting an error in the for loop on the line that has term.sets_term_id. This is the error TermsDoesNotExist: Instance matching query does not exist: If I do vars(term) then sets_terms_id is an option. Why am I getting that error and how do I fix it?</p>

<pre><code>def get_api_response(id):
    response = {}
    print("id is " + str(id))
    try:
        sets = models.Sets.select().where(models.Sets.user_id == id)

    except models.DoesNotExist:
        return json.loads({'error' : 'that set does not exist'})
    else:
        print("it was successful")
        for term in sets:
            print(term.sets_term_id)
</code></pre>

<p>Here are my Sets and Terms models</p>

<pre><code>class Terms(UserMixin, BaseModel):
    term_id = CharField()
    sets_id = CharField()
    rank = IntegerField()
    term = TextField()
    definition = TextField()

    @classmethod
    def include_term(cls, set_id, term_id, definition, rank, term, **kwards):
        try:
            cls.select().where(cls.term_id == term_id).get()
        except cls.DoesNotExist:
            print("putting term into db")
            concept = cls(
                sets_id = set_id,
                term_id = term_id,
                definition = definition,
                rank = rank,
                term= term)
            concept.save()
            print(concept.term)
            print("term saved to db")
            return concept
        else:
            raise Exception("Term with that id already exists")

class Sets(UserMixin, BaseModel):
    user_id = CharField()
    name_set = CharField()
    #created_date = DateField()
    #modified_date = DateField()
    #published_date = DateField()
    sets_term_id = ForeignKeyField(Terms, to_field="sets_id")

    @classmethod
    def include_set(cls, user_id, name_set, sets_term_id, **kwards):
        try:
            cls.select().where(
                (cls.name_set == name_set) | (cls.sets_term_id == sets_term_id)
            ).get()
        except cls.DoesNotExist:
            print("putting set into db")
            quizlet_set = cls(
                user_id = user_id, 
                name_set = name_set,
                sets_term_id = sets_term_id)
            print(quizlet_set.name_set)
            quizlet_set.save()
            print("set saved in db")

            return quizlet_set
        else:
            raise Exception("Set with that name already exists")  
</code></pre>