title: Why do I get a KeyError on a Model in Django?
body: <p>I am getting a KeyError: 'conversation' on the line <code>conv = ans.conversation</code> in the code section:</p>
  
  <pre><code>answers = Answers.objects.all()
  
  for ans in answers:
      conv = ans.conversation
      ...
  </code></pre>
  
  <p>My model 'Answers' looks like this:</p>
  
  <pre><code>class Answers(models.Model):
      conversation = models.ForeignKey(Conversation)
      ...
  </code></pre>
  
  <p>I get the error sometimes, so if I run the code, I get the correct result a few times, but eventually within the for loop, sometimes the line <code>conv = ans.conversation</code> fails. Why do you think an error like this could ocurr?</p>
  
  <p>The entire error trace is here:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 164, in _get_
      rel_obj = self.field.get_cached_value(instance)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/fields/mixins.py", line 13, in get_cached_value
      return instance._state.fields_cache[cache_name]
  KeyError: 'conversation'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/webapps/municipio/municipio/reportes/views.py", line 153, in get_whats_data
      conv = ans.conversation
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 178, in _get_
      rel_obj = self.get_object(instance)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 145, in get_object
      return qs.get(self.field.get_reverse_related_filter(instance))
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/query.py", line 402, in get
      num = len(clone)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/query.py", line 256, in _len_
      self._fetch_all()
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/query.py", line 1242, in _fetch_all
      self._result_cache = list(self._iterable_class(self))
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/query.py", line 55, in _iter_
      results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1100, in execute_sql
      cursor.execute(sql, params)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
      return super().execute(sql, params)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
      return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
      return executor(sql, params, many, context)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
      return self.cursor.execute(sql, params)
    File "/webapps/municipio/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
      return self.cursor.execute(query, args)
    File "/webapps/municipio/env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 209, in execute
      res = self._query(query)
    File "/webapps/municipio/env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 315, in _query
      db.query(q)
    File "/webapps/municipio/env/lib/python3.6/site-packages/MySQLdb/connections.py", line 226, in query
      _mysql.connection.query(self, query)
    File "/webapps/municipio/env/lib/python3.6/site-packages/gunicorn/workers/base.py", line 196, in handle_abort
      sys.exit(1)
  SystemExit: 1
  </code></pre>