Opened 3 years ago

Closed 3 years ago

#33075 closed Bug (invalid)

'__date' returns None in MySQL while it returns date object in Sqlite3

Reported by: pikicode Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords: mysql
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by pikicode)

database: mysql 5.7
django version: 3.2
python version: 3.8.1

Model.objects.values('some_datetime_field__date',) returns None in MYSQL

class Inbound(models.Model):
    effective_date = models.DateTimeField(null=False, blank=True)
    number = models.IntegerField()
    # other fields.

daily_changes = Inbound.objects.all().values('effective_date__date')\
  .annotate(total_change=Sum('number')).
Inbound.objects.values('effective_date__date')

The code just returns Nones in Mysql. But it returns date object with Sqlite

Change History (2)

comment:1 by pikicode, 3 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 3 years ago

Component: UncategorizedDatabase layer (models, ORM)
Keywords: mysql added
Resolution: invalid
Status: newclosed

When USE_TZ is True, fields are converted to the current time zone before filtering (see __date docs). This requires time zone definitions in the database. Please check that mysql_tzinfo_to_sql is loaded to the time zone tables.

Note: See TracTickets for help on using tickets.
Back to Top