即使USE_TZ=True,SQLite后端也不支持时区感知时间



我现在正在开发一个小型django项目,该项目需要使用可感知的datetime.time对象。

当用户注册时,他必须填写一个时间输入。然后,这些数据在我的views.py文件中被转换为一个感知时间对象,就像这样:

...
if form.cleaned_data['reviews_time']:
form.cleaned_data['reviews_time'] = form.cleaned_data['reviews_time'].replace(tzinfo=get_current_timezone())
else:
form.cleaned_data['reviews_time'] = time(hour=0,minute=0,tzinfo=get_current_timezone())
*save the created user account*
...

问题是,当我提交表单时,我会收到以下错误:SQLite backend does not support timezone-aware times.即使我启用了USE_TZ。

我想知道为什么会发生这个错误,以及如何修复它。如果有人能帮助我,我将非常感激(并随时要求额外的代码/解释)enter code here

在我自己的例子中,USE_TZ被设置为False。更改为之后USE_TZ=真一切都很好。

最新更新