12π
I encountered this same problem, also with a server that is normally running with the UTC+2 (in my case, Europe/Oslo).
It turned out that the system zoneinfo files on my server (Centos 7) were corrupted, which became evident in pg_timezone_names
.
postgres=# select * from pg_timezone_names where name like 'UTC';
name | abbrev | utc_offset | is_dst
------+--------+------------+--------
UTC | CEST | 02:00:00 | t
(1 row)
After running yum update tzdata
to update my serverβs timezone files, and restarting the PostgreSQL server, the issue appears to be resolved.
postgres=# select * from pg_timezone_names where name like 'UTC';
name | abbrev | utc_offset | is_dst
------+--------+------------+--------
UTC | UTC | 00:00:00 | f
(1 row)
My guess it that I might previously have run cat /usr/share/zoneinfo/Europe/Oslo > /etc/localtime
without first removing /etc/localtime
to change the timezone on the system, effectively overwriting the zoneinfo for UTC with the zoneinfo for Europe/Oslo.
50π
For 18/06/2021 this is a known issue, which comes from the psycopg-2/psycopg2-binary packages. Fortunately, they already have an open issue on their GitHub page, so hopefully it gets fixed soon.
As a temporary fix, you can pin the version in your requirements.txt
to psycopg2-binary>=2.8,<2.9
or psycopg2>=2.8,<2.9
, depending on what package you are using.
Thanks to @vinkomlacic for mentioning this in comments.
- [Django]-Django: Does prefetch_related() follow reverse relationship lookup?
- [Django]-Django: How to check if the user left all fields blank (or to initial values)?
- [Django]-Programmatically using Django's loaddata
15π
Hereβs a simple workaround that I found to fix the issue for me.
That is to set:
USE_TZ = False
This helps to solve the issue.
By default it is set to True, so that gives the error for me when I use PostgreSql on Heroku. Maybe some synchronization happens between Django engine and the database.
- [Django]-How can I handle Exceptions raised by dango-social-auth?
- [Django]-Retrieving list items from request.POST in django/python
- [Django]-How to resolve "django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: foo" in Django 1.7?
6π
If you are using psycopg2 2.9, downgrade to psycopg2==2.8.6 or pip3 install psycopg2-binary==2.8.6.
This issue is caused by a recent update to psycopg2, version 2.9.
- [Django]-How can I build multiple submit buttons django form?
- [Django]-Django role based views?
- [Django]-Django- nginx: [emerg] open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/myproject:11
1π
Thanks very much for the answer KFH, it helped me a lot. In case you are using Ubuntu, the following should fix it:
sudo apt install tzdata --reinstall
The problem was the same for me, as I had previously run sudo cp /usr/share/zoneinfo/America/Montreal /etc/localtime
which messed with my postgres db. Re-installing tzdata
and restarting postgres fixed the problem for me.
- [Django]-How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files?
- [Django]-SyntaxError: Generator expression must be parenthesized
- [Django]-Django related_name for field clashes
0π
The error got solved for me on windows by installing both: psycopg2==2.8.6 and psycopg2-binary==2.8.6 and uninstalling the latest version of any of both that were installed.
- [Django]-How can I unit test django messages?
- [Django]-Django Blob Model Field
- [Django]-AssertionError: database connection isn't set to UTC