Update the table's ID column when you remove a row from a model.



  • When I remove a row from a table I want the ID column to be updated, that is the rows after the one deleted to have minus 1 (if can be updated when I remove multiple rows at once is even better). Does QSqlRelationalTableModel has something for updating the table's ID column or I must do that manualy?

    (I also use a proxy model with QSqlRelationalProxyModel. I don't know if that is relevant).



  • Database id fields do not work that way. The whole point of that field is that it does not change.



  • I'm not quite sure about the ID you are referring to but if you are talking about the ID as a primary key (as in the relational table model) then no, there is no such functionality.

    Besides that (and yes, I know this is philosopihcal question) you should never alter or reuse a primary key in a database, especially if it is auto-generated (sequenced). If you want a continous numbering of your items either use an additional column or a 'virtual' column which is created no the fly. But do not abuse your primary key for this.



  • Ok, I wont modify it. I'm sorry I didn't knew that.

    Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.