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. Pyqt6 bug with QSqlRelationalTableModel and Postgresql (version 13)

Pyqt6 bug with QSqlRelationalTableModel and Postgresql (version 13)

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 4 Posters 871 Views 1 Watching
  • 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.
  • J Offline
    J Offline
    Jelutho
    wrote on last edited by
    #1

    The following code works perfectly with Sqlite3 but not with Postgres. No bug but the returned table is always empty...

    self.model = QSqlRelationalTableModel(db=db)        
    self.model.setTable("hr_employee")
    self.model.setRelation(2, QSqlRelation("Job", "job_id", "name"))
    self.model.select()
    self.table.setModel(self.model)
    

    if I remove this line, it works !

    self.model.setRelation(2, QSqlRelation("Job", "job_id", "name"))
    

    I would appreciate any help because I am stuck.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      How should we know what's wrong when you don't show us e.g. the table schemas and which Qt version you use?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jelutho
        wrote on last edited by
        #3

        Hello

        I use PyQt6 and table shema looks like this

        hr_employee 
            - id 
            - name
           - job_id
        
        hr_job
            -id
            -name
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on last edited by
          #4

          @Jelutho said in Pyqt6 bug with QSqlRelationalTableModel and Postgresql (version 13):

          QSqlRelation("Job", "job_id", "name")

          You showed your schema but it doesn't have a "Job" table which is the first argument of your QSqlRelation.

          J 1 Reply Last reply
          2
          • M mchinand

            @Jelutho said in Pyqt6 bug with QSqlRelationalTableModel and Postgresql (version 13):

            QSqlRelation("Job", "job_id", "name")

            You showed your schema but it doesn't have a "Job" table which is the first argument of your QSqlRelation.

            J Offline
            J Offline
            Jelutho
            wrote on last edited by
            #5

            @mchinand

            Hello

            the code is...

            self.model_employee.setRelation(3, QSqlRelation("hr_job", "job_id", "name"))
            

            ...and it still doesn' work.

            JonBJ 1 Reply Last reply
            0
            • J Jelutho

              @mchinand

              Hello

              the code is...

              self.model_employee.setRelation(3, QSqlRelation("hr_job", "job_id", "name"))
              

              ...and it still doesn' work.

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

              @Jelutho
              Can you use something like
              [override virtual protected]QString QSqlRelationalTableModel::selectStatement() const
              to examine what SQL statements are being sent to the database?

              Meanwhile, your column number has now changed to 3 which wouldn't work with the schema you showed, we don't know why. And originally you said the code worked in SQLite, but then you say the table is not actually named Job but hr_job. You may be right and there is a Postgresql vs SQLite issue here but you're not very consistent with what you claim/show so it's hard to be sure.

              1 Reply Last reply
              2

              • Login

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