Django/MySQl how to fix Database returned an invalid datetime value. Are time zone definitions for your database installed?
What Happened
After moving my Django
app - which was working as expected - from a VPS to shared hosting with Cpanel
I changed Database from PostgresSQL
to MySQL
, whenever I open an object that has created_at
field which is a Datetime Field
I Get this error.
Error
Database returned an invalid datetime value. Are time zone definitions for your database installed?
What I've tried
After some searching, I've found out that it can be fixed by running this command in terminal
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
That command should populate the Timezone tables in my database.
The Problem
I can't run the comment mentioned above as am using Cpanel
shared hosting and am very limited on my choices and commands that I can run using terminal
. so I tried to run it I got this error
What I need
I think the solution now is to find a way to populate the timezone tables on the Mysql
database using only PhpMyAdmin
and not using the terminal
Interestingly this error is addressed in Django's docs,
I get an error “Are time zone definitions for your database installed?”
If you are using MySQL, see the Time zone definitions section of the MySQL notes for instructions on loading time zone definitions.
once we check inside the Time zone definitions, we read
If you plan on using Django’s timezone support, use mysql_tzinfo_to_sql to load time zone tables into the MySQL database. This needs to be done just once for your MySQL server, not per database.
Knowing that OP can run that, I'd get in touch with the hosting provider to do that.