Error "SQLite backend does not support timezone-aware datetimes when USE_TZ is False" when saving DateField in Django

I am working on a Django project using an SQLite database and encountered the following error when trying to save records to the database:

SQLite backend does not support timezone-aware datetimes when USE_TZ is False.

In my model, I am using two DateField fields as follows:

class Announcement(models.Model):   
    date_start= models.DateField(null=True, blank=True)
    date_end = models.DateField(null=True, blank=True)

In my code, I am assigning dates like this:

from datetime import datetime, timedelta
from coreapp.views.base.base_view import BaseView
from coreapp.services import utils
from announcement.models import Announcement

class FormAnnouncement(BaseView):
    
    def post(self, request):

        form = utils.get_form_from_json(request)

        date_start = datetime.strptime(form['date_start'], "%Y-%m-%d").date() if 'date_start' in form and form['date_start'] else None
        date_end = datetime.strptime(form['date_end'], "%Y-%m-%d").date() if 'date_end' in form and form['date_end'] else None
        
        new_Announcement = Announcement.objects.get(id=announcement_id)
        
        new_Announcement.date_start = date_start + timedelta(days=1)
        new_Announcement.date_end = date_end + timedelta(days=1)
        new_Announcement.save()

Relevant settings in settings.py:

USE_TZ = False

Database: SQLite

From what I understand, this error usually occurs when working with DateTimeField or datetime, but in my case, I am only using DateField, which should handle just dates without the time component.

Does anyone know what could be causing this error and how I can resolve it without changing USE_TZ in the settings.py file?

Back to Top