2

i tried to TruncDay in django to turn date into day format , i use mysql version 8.0 with windows 10 this my settings.py

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

date = models.DateTimeField(auto_now_add=True)

MyModel.objects.annotate(day=TruncDay('date'))#others

and i tried to run mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql; but it raise this error while i run this command in mysql shell

ERROR: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql' at line 1

i also downloaded times files https://dev.mysql.com/downloads/timezones.html
and also my django project raise this error also

Database returned an invalid datetime value. Are time zone definitions for your database installed?

art_cs
  • 683
  • 1
  • 8
  • 17
  • The command that begins `mysql_tzinfo_to_sql` is meant to be run from the command line, not from within mysql. – RGoodman Jun 25 '20 at 18:06
  • no , you wrong you should type it in mysql shell – art_cs Jun 25 '20 at 18:20
  • @art_cs nope, the `|`s are for the OS shell to run additional commands, the `mysql ...` would start a mysql shell session. – user3783243 Jun 25 '20 at 18:56
  • dont work you say (mysql_tzinfo_to_sql /usr/share/zoneinfo mysql -u root mysql;) – art_cs Jun 25 '20 at 18:59
  • @user3783243 may you explain more please – art_cs Jun 25 '20 at 19:07
  • @art_cs The `|` is an operator in the linux shell (maybe windows?) and it pass the commands on the left to the function call on the right. So this is running `mysql_tzinfo_to_sql /usr/share/zoneinfo` then executing `mysql -u root mysql` which opens a mysql shell as the `mysql` user. This is meant for command line, not mysql shell. – user3783243 Jun 25 '20 at 20:55
  • didnt work in command line (cmd) in windows , and in in the mysql docs say to run in mysql shell – art_cs Jun 25 '20 at 21:01
  • 1
    I think you are misreading the docs. `shell` is the linux shell, not `mysql` see the part `and send the output into the mysql program` it wouldn't need to send it to the program if it was being executed in the program. This may not be the right syntax for Windows.. The pipes are for linux execution. – user3783243 Jun 26 '20 at 03:12

2 Answers2

1

Database returned an invalid datetime value. Are time zone definitions for your database installed?

I got the same error after upgrading django from 2.2 to 3.2 and this was the first stack overflow question I found.

For me the following fixed the error: https://stackoverflow.com/a/21571350/10162645

undefined
  • 84
  • 1
  • 10
-1

Just change the settings.py from

USE_TZ = True

to

USE_TZ = False

This worked for me.

Hosein
  • 369
  • 3
  • 8
  • This is no solution to the problem, it's avoiding it. Answers from this post helped me https://stackoverflow.com/questions/21351251/database-returned-an-invalid-value-in-queryset-dates/21571350#21571350 – Nikita Tonkoskur Jul 03 '23 at 17:03