[Django]-Django Attribute error 'datetime.timedelta' object has no attribute 'decode'

3👍

The problems seems to be related with the database connector you’re using.

My solution to this problem was using mysql-connector-c instead of mysql-client when connecting to the database.

I used this lib (mysqlclient 1.4.2.post1) to solve my issue but there is another option at the end.

Steps were:

  1. pip install mysql-connector-python
  2. pip install mysqlclient
  3. change the database settings in my settings file (base.py in my case)
    • from 'default': env.db('DB_DEFAULT', default=f'mysql-connector://root:password@{HOST_MYSQL}:3306/YOUR_DB')
    • to 'default': env.db('DB_DEFAULT', default=f'mysql://root:password@{HOST_MYSQL}:3306/YOUR_DB')

Another option is changing the use_pure from db options to true, you can do it by adding the ?use_pure=True querystring to you connection URL.

This last one could affect the connection performance because it assures that it will be made with Python’s pure connector and not the compile version of it.

2👍

If you use ‘mysql-connector-python’ Try using version 8.0.5 instead. I had the same issue when using the newest version of ‘mysql-connector-python’.

0👍

don’t use:

 order_dispatch_time = models.TimeField(default='00:00', max_length=100)
 order_delivered_time = models.TimeField(default='00:00', max_length=100)

instead use :

 import datetime
  <...you model ...>
 order_dispatch_time = models.TimeField(default=datetime.time(00,00))
 order_delivered_time = models.TimeField(default=datetime.time(00,00))

Leave a comment