Opened 4 years ago
Closed 4 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 )
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 , 4 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 4 years ago
| Component: | Uncategorized → Database layer (models, ORM) |
|---|---|
| Keywords: | mysql added |
| Resolution: | → invalid |
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
When
USE_TZisTrue, fields are converted to the current time zone before filtering (see __date docs). This requires time zone definitions in the database. Please check thatmysql_tzinfo_to_sqlis loaded to the time zone tables.