title: Django: Warning: Incorrect integer value: 'UnlocksBranch' for column 'type_id' at row 1
body: <p>I am writing a Django app that pulls data from a Bugzilla database and I am having trouble getting the flags.</p>
  
  <pre><code>class Bugzilla_bugs(models.Model):
      class Meta:
          db_table = 'bugs'
  
      bug_id = models.IntegerField(primary_key=True)
      ...         
  </code></pre>
  
  <p>The flagtypes table which describes all of the different flag names and what they mean.</p>
  
  <pre><code>class Bugzilla_flagtypes(models.Model):
      class Meta:
          db_table = 'flagtypes'
  
      name = models.CharField(max_length=50,unique=True)
      description = models.TextField()
      ...
  </code></pre>
  
  <p>The flags table, which is a one-to-many mapping of bug_id, type_id and status values for each bug.</p>
  
  <pre><code>class Bugzilla_flags(models.Model):
      class Meta:
          db_table = 'flags'
  
      type_id = models.ForeignKey(Bugzilla_flagtypes,related_name='flagtype',db_column='type_id',to_field='name')
      status = models.CharField(max_length=50)
      bug_id = models.ForeignKey(Bugzilla_bugs,related_name='flaglines',db_column='bug_id',to_field='bug_id')
  </code></pre>
  
  <p>When I try to get the flaglines for a particular bug:</p>
  
  <pre><code>bug = Bugzilla_bugs.objects.using('bugzilla').get(bug_id=12345)
  bug.flaglines.get(type_id="UnlocksBranch")
  </code></pre>
  
  <p>I get the exception:</p>
  
  <pre><code>&gt;&gt;&gt; bug.flaglines.get(type_id__name="UnlocksBranch")
  Traceback (most recent call last):
    File "&lt;console&gt;", line 1, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 92, in manager_method
      return getattr(self.get_queryset(), name)(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 351, in get
      num = len(clone)
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 122, in __len__
      self._fetch_all()
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 966, in _fetch_all
      self._result_cache = list(self.iterator())
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 265, in iterator
      for row in compiler.results_iter():
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 700, in results_iter
      for rows in self.execute_sql(MULTI):
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
      cursor.execute(sql, params)
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 81, in execute
      return super(CursorDebugWrapper, self).execute(sql, params)
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute
      return self.cursor.execute(sql, params)
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 128, in execute
      return self.cursor.execute(query, args)
    File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 176, in execute
      if not self._defer_warnings: self._warning_check()
    File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 92, in _warning_check
      warn(w[-1], self.Warning, 3)
  Warning: Incorrect integer value: 'UnlocksBranch' for column 'type_id' at row 1
  </code></pre>
  
  <p>I am trying to use the 'get' method to get the value of the 'status' field in the flags table.</p>
  
  <p>If I try to use flaglines to get query the numerical type_id, I get DoesNotExist.</p>
  
  <pre><code>&gt;&gt;&gt; bug.flaglines.get(type_id=20)
  Traceback (most recent call last):
    File "&lt;console&gt;", line 1, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 460, in __repr__
      u = six.text_type(self)
    File "/home/shubbard/django/cpe/dev/cpe/bugzilla/models.py", line 160, in __unicode__
      return unicode(self.type_id)
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 572, in __get__
      rel_obj = qs.get()
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 357, in get
      self.model._meta.object_name)
  DoesNotExist: Bugzilla_flagtypes matching query does not exist.
  </code></pre>
  
  <p>I know that the bug has that flag set.</p>
  
  <pre><code>mysql&gt; select * from flags where bug_id=12345;
  +-------+---------+--------+--------+
  | id    | type_id | status | bug_id |
  +-------+---------+--------+--------+
  | 71732 |      29 | +      |  12345 |
  | 72538 |      41 | +      |  12345 |
  | 72547 |      12 | +      |  12345 |
  | 72548 |      31 | ?      |  12345 |
  | 72549 |      33 | ?      |  12345 |
  | 72550 |      20 | ?      |  12345 |
  | 72551 |      36 | ?      |  12345 |
  +-------+---------+--------+--------+
  7 rows in set (0.01 sec)
  </code></pre>
  
  <p>What am I doing wrong?</p>