SET TIMEZONE in raw query

Asked

Viewed 70 times

0

The raw query below shows the following error:

query = Resume.objects.raw("""
            SET TIMEZONE='America/Sao_Paulo';
            SELECT id, datetime_now FROM resume;
""")

raise AssertionError("database connection isn't set to UTC")
AssertionError: database connection isn't set to UTC

If you remove SET TIMEZONE the error does not occur.

The database is configured as follows for Timezone:

# show timezone;
     TimeZone      
-------------------
 America/Sao_Paulo
(1 row)

The Settings.py

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Sao_Paulo'
USE_I18N = True
USE_L10N = False
USE_TZ = True

What could be causing this?

  • pq vc are using sql commands if you can use the Django ORM? vc can get these settings from settings.py easily

1 answer

0

The problem occurs when the environment variable is declared in Settings.py:

USE_TZ = True

To use cursor or raw query, this should be removed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.