Unsolved 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:self.date = self.view_date.data.date() self.date = str(self.date)
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 ofQDate
: maybe your variable type allowsself.date = self.view_date.data.datetime()
. - Try forcing conversion to Python datetime:
self.date = datetime.datetime(self.view_date.data.date())
. - Look up the documentation for Postgresql/SQLAlchemy to see what exactly it accepts for a date/time: e.g.
str(self.date)
might be along the right lines but may require a particular format, not the default.
- Try
-
@JonB The text () method solves my problem, as it returns the exact string as an example: 1/31/2021.
So stay:self.date = self.view_date.data.text()
-
@_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!