title: "Truncated incorrect DOUBLE value: X_XX"
body: <p>Django's ORM just isn't clicking for me, but I intend to spend the weekend reading through the <a href="https://docs.djangoproject.com/en/1.11/topics/db/" rel="nofollow noreferrer">documentation</a> in order to make it click.</p>
  
  <p>Meanwhile, I have an issue I need to resolve that I haven't been able to.</p>
  
  <p>The first I had was here, which was resolved with the answer provided:</p>
  
  <p><a href="https://stackoverflow.com/questions/48332604/valueerror-invalid-literal-for-int-with-base-10-seems-to-be-related-to-foreig">ValueError: invalid literal for int() with base 10 seems to be related to ForeignKey</a></p>
  
  <p>I have modified my query to:</p>
  
  <pre><code># data['product_id] = 78
  # returns A_17
  product_code = Products.objects.get(id=data['product_id']).code
  
  # this is where the error occurs
  print(ProductPositions.objects.filter(product_code__code=product_code))
  </code></pre>
  
  <blockquote>
    <p>/mnt/c/dev/current/client/.venv/client/lib/python3.6/site-packages/pymysql/cursors.py:166: Warning: (1292, "Truncated incorrect DOUBLE value: 'A_15'")</p>
    
    <p>result = self._query(query)
    </p>
  </blockquote>
  
  <p>I am not even sure why it is looking at <code>A_15</code> because it should only be filtering on <code>A_17</code>, so that is one issue I don't understand</p>
  
  <p>To explain these tables because I don't think it is really intuitive. The <code>Products</code> will look something like this (with columns not relevant to this removed):</p>
  
  <pre><code>-- Products table
  id     code
  --------------
  77     A_16
  78     A_17
  81     M_15
  </code></pre>
  
  <p>There are multiple of the <code>code</code> in the <code>ProductPositions</code>. <code>code</code> is more like a line of products and and <code>product_no</code> (which I haven't got to yet and is the next step) are the products in that line. Ultimately, I am trying to get the description, but only at the point of filtering <code>A_17</code> currently. So it will look like:</p>
  
  <pre><code>-- ProductPositions table
  product_code         product_no       description
  -------------------------------------------------
  A_17                 ABC123           Widget 1
  A_17                 DEF456           Widget 2
  A_17                 GHI789           Widget 3
  A_16                 ABC123           Widget 1
  A_16                 DEF456           Widget 2
  A_16                 GHI789           Widget 3
  </code></pre>
  
  <p>These are the models for each:</p>
  
  <pre><code>class Products(models.Model):
      id = models.AutoField(primary_key=True)
      code = models.CharField(unique=True, max_length=16)
      name = models.CharField(max_length=255, blank=True, null=True)
      short_name = models.CharField(max_length=128)
  
  class ProductPositions(models.Model):
      product_code = models.ForeignKey(Products, db_column='product_code', null=False)
      product_no = models.DecimalField(unique=True, max_digits=12, decimal_places=1, primary_key=True)
      product_title = models.CharField(max_length=255)
      product_description = models.TextField()
  
      def __str__(self):
          return self.product_description
  
      class Meta:
          db_table = 'Product_Positions'
          unique_together = ('product_code', 'product_no')
  </code></pre>
  
  <p>Also, it seems like it might be an error generated by the database. However, when I do the following in <code>./manage.py shell</code> to see a list of raw SQL queries, nothing comes up (only one connection and it isn't named):</p>
  
  <pre><code>&gt;&gt;&gt; from django.db import connection
  &gt;&gt;&gt; connection.queries
  []
  </code></pre>
  
  <p>Anyway, ultimately trying to get to <code>ProductPositions.objects.filter(product_code__code=product_code).filter(product_no=data['product_no'].description</code>, but running into issues every step of the way.</p>
  
  <p><strong>And to be clear on the issue: a string is being passed to <code>varchar</code> field, but the error is coming back with <code>double</code>. Why?</strong></p>