Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. I cannot add the "date" to the database as it is not compatible with QDate

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

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _jao_victor_
    wrote on last edited by _jao_victor_
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • _ _jao_victor_

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @_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 self.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.
      _ 1 Reply Last reply
      3
      • JonBJ JonB

        @_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 self.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.
        _ Offline
        _ Offline
        _jao_victor_
        wrote on last edited by
        #3

        @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()
        
        Pablo J. RoginaP 1 Reply Last reply
        0
        • _ _jao_victor_

          @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()
          
          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @_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!

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved