I'm dockerizing my Django application. Since I changed my database from SQLite to Postgres the migration fails and I get this error:
RuntimeWarning: DateTimeField Posts.created_at received a naive datetime (2020-01-19 14:26:30.893128) while time zone support is active.
warnings.warn("DateTimeField %s received a naive datetime (%s)"
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.CannotCoerce: cannot cast type time without time zone to timestamp with time zone
LINE 1: ..." TYPE timestamp with time zone USING "created_at"::timestam...
I have searched the other issues and tried this fix https://stackoverflow.com/a/20106079/7400518
I was using datetime.now()
then I changed it to timezone.now()
but I'm still getting the same error.
This is the related lines from models.py
from django.utils import timezone
class Posts(models.Model):
created_at = models.DateTimeField(default=timezone.now(), blank=True)