Opened 3 years ago

Last modified 3 years ago

#33602 closed Bug

when use date_hierarchy in admin, it report a error. django 3.2.12, mysql-connector-python8.0.28, mysql server 8.0.28 — at Initial Version

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

Description

\site-packages\django\db\backends\mysql\operations.py line 58

def date_trunc_sql(self, lookup_type, field_name, tzname=None):

field_name = self._convert_field_to_tz(field_name, tzname)
fields = {

'year': '%%Y-01-01',
'month': '%%Y-%%m-01',

} # Use double percents to escape.

the problem is here.

'year': '%%Y-01-01',

'month': '%%Y-%%m-01',

this will generate the sql.
SELECT DISTINCT CAST(DATE_FORMAT([table name], '%%Y-01-01') AS DATE) AS `datefield

the format %%Y-01-01 is not right for mysql.

Change History (0)

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