I am trying to store timezone aware datetime with python and postgresql and there is always one issue or the other
i get the following error when trying to save a user into postgresql database
asyncpg.exceptions.DataError: invalid input for query argument $1: datetime.datetime(2021, 6, 13, 21, 12, 1... (can't subtract offset-naive and offset-aware datetimes)
here is function that saves user into database
from datetime import datetime
import pytz
def save_user(user: auth_schema.UserCreate):
query = "INSERT INTO users VALUES (nextval('users_id_seq'), :email, :password, '', '', :created_on, :last_login, False, True, :is_superuser)"
return database.execute(query, values={"email": user.email, "password": user.password, "created_on": datetime.now(pytz.utc), "is_superuser": False})
so how do i get rid of the error?
asyncpg.exceptions.DataError: invalid input for query argument $1: datetime.datetime(2021, 6, 13, 21, 12, 1... (can't subtract offset-naive and offset-aware datetimes)
UPDATE:
created_on
column of users table is of type timestamp