Error: Mysql backend does not support Timezone-Aware datetimes when USE_TZ is False

Asked

Viewed 27 times

0

I’m having a problem in the pagseguro api, I’m using Django 1.8 when I try to send a payment it presents the error "Mysql backend does not support Timezone-Aware datetimes when USE_TZ is False."

I can’t change the USE_TZ configuration to True, because it will interfere with other parts of the application. I’ve changed where I was using Timezone.now() to datetime.now() and yet you still need this error someone has a solution to this ?

Follow the code of how this the api function:

def checkout(self):
    self.build_params()
    headers = {
        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
    }
    response = requests.post(
        self.checkout_url, self.params, headers=headers
    )

    data = {}

    if response.status_code == 200:
        root = xmltodict.parse(response.text)
        data = {
            'code': root['checkout']['code'],
            'status_code': response.status_code,
            'date': parse(root['checkout']['date']),
            'redirect_url': '{0}?code={1}'.format(
                self.redirect_url, root['checkout']['code']
            ),
            'success': True
        }
        checkout_realizado_com_sucesso.send(
            sender=self, data=data
        )
    else:
        data = {
            'status_code': response.status_code,
            'message': response.text,
            'success': False,
            'date': datetime.datetime.now()
        }
        checkout_realizado_com_erro.send(
            sender=self, data=data
        )

    checkout_realizado.send(
        sender=self, data=data
    )
    return data
  • in the project’s Setting changed from USE_TZ = True to USE_TZ = False , this USE_TZ uses the time pattern defined by TIME_ZONE that in Django is in the standard Grigo, to change to the br TIME_ZONE = 'America/Sao_paulo' .. So then what I mentioned case does not say anything about the result.

  • Opa, so in the case is already with TIME_ZONE from são paulo, the business and that if you use USE_TZ, all the places that use datetime to work. So the solution I thought would temporoaria mind was to remove this validation from the mysql app but I don’t think it’s the best way .

  • I think that it is not even in djangozinho this in your database mysql should be in another time zone improperly when the project is in the br schedule and the database in the pattern of this inconsistency and this delay to finalize the project.. I think the question would be for mysql, see if time zone the way mysql is dealing with the schedules is in the pattern.

No answers

Browser other questions tagged

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