I'm using Django 2.2
I have a created
field of DateTime type.
I'm using following command to filter the records which are greater than specific date
q.filter(created__year__gte=2020, created__month__gte=3, created__day__gte=1)
In my database there are records for March (3) month and more but not for February (2).
When above command is executed, it gives me queryset list of data greater than March 1. But when I use the following command
q.filter(created__year__gte=2020, created__month__gte=2, created__day__gte=28)
Where month is February (2), it is not giving any data and the queryset is blank.
Using datetime
object gives error
received a naive datetime (2020-03-01 00:00:00) while time zone support is active
Why filter is not working with gte
even when month is less than 3
?
The error was not with the Django setup, instead it was with the MySQL configuration due to missing timezone data.
Check this answer for how to resolve this error
https://stackoverflow.com/a/60844090/3719167