Django2.1.4 ORM seems to have a significant BUG!

use Django2.1.4 to do web single page application (Python3.7.1) for the first time. Models.py uses models.IntegerField () to define orm mapping, mysql database version 8.0.12-winx64, using INT type field. When the field is non-zero , the result can be queried normally. When the field value is 00:00, the result can be queried normally. No matter using ORMQuerySet or native SQL (RawQuerySet, cursor), the result of querying 0 value is None. It is suspected that IntegerField () treats 0 value as False. When you use models.CharField (), you can query the "0" value normally when you change the database field from INT to VARCHAR. I would like to ask you if there is a way to crack it. Thank you so much!

-sharp 
def querylist(request):
    qs = ExcelView.objects.get(case_no="20191090500344")
    print("qs-----------------------------")
    print(type(qs))
    print(qs.case_no, qs.payment_amount, qs.current_added_score, qs.current_total_score)
    print("rqs----------------------------")
    rqs = ExcelView.objects.raw("select * from caseinfo_excelview where ``=20191090500344")
    print(type(rqs))
    for v in rqs:
        print(v.case_no, v.payment_amount, v.current_added_score, v.current_total_score)
    print("cursor-------------------------")
    cursor = connection.cursor()
    cursor.execute("select * from caseinfo_excelview where ``=20191090500344")
    raw = cursor.fetchone()
    print(type(raw))
    print(raw)
    return render(request, "querylist.html", {})
-sharp -*- coding: UTF-8 -*-
from django.db import models

-sharp Create your models here.
class ExcelView(models.Model):
    case_no = models.CharField(db_column="", max_length=20, primary_key=True) -sharp 
    amount_of_penalty = models.IntegerField(db_column="()", default=0) -sharp ()
    amount_receivable = models.IntegerField(db_column="()", default=0) -sharp ()
    payment_amount = models.IntegerField(db_column="", default=0) -sharp 
    current_added_score = models.IntegerField(db_column="", default=0) -sharp 
    current_total_score = models.IntegerField(db_column="", default=0) -sharp 
    def __str__(self):
        return self.case_no

    def __unicode__(self):  -sharp __str__ on Python 3
        return self.case_no

    -sharp def __next__(self):
    -sharp     return [field.value_to_string(self) for field in ExcelView._meta.fields]

    -sharp def __iter__(self):
    -sharp     return self

    class Meta:
        db_table = "caseinfo_excelview"

Apr.20,2022
The

problem has been located and resolved. It turns out that it's not the Django pot, it's the mysql driver. I use mysql-connector-python==8.0.13, which has a lot of bug. I have to report all kinds of weird errors when using the ORM aggregation function, and there are a lot of complaints on stack overfolw. With mysqlclient, there is no problem with the above zero-value Integer query result as None, and there is nothing wrong with using the aggregate function.


Don't always think about making big news.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3259a-2be13.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3259a-2be13.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?