Important: Please read the Qt Code of Conduct -

I cannot add the "date" to the database as it is not compatible with QDate

  • I have a QDateEdit field on my form and every time I try to add this value to the database an error is returned:

    sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'QDate'

    According to the message, the QDate type is not supported by the database (Postgresql).
    I've tried to convert to string like this: = = str(

    Does anyone have any idea how I can get around this?

  • @_jao_victor_
    You don't help us by failing to say whether you are using PyQt or PySide. And FWIW I don't think the error comes from the database, I think it comes from the SQLAlchemy library you are choosing to use.

    • Try QDateTime instead of QDate: maybe your variable type allows =
    • Try forcing conversion to Python datetime: = datetime.datetime(
    • Look up the documentation for Postgresql/SQLAlchemy to see what exactly it accepts for a date/time: e.g. str( might be along the right lines but may require a particular format, not the default.

  • @JonB The text () method solves my problem, as it returns the exact string as an example: 1/31/2021.
    So stay: =

  • @_jao_victor_ said in I cannot add the "date" to the database as it is not compatible with QDate:

    solves my problem

    if your issue is solved, please don't forget to mark your post as such!

Log in to reply