I am trying to teach myself database features, and I have come into a problem. I have a relational table model for a mysql database table, but insertRecord fails. I am sure I am not understanding something, probably at a fundamental level. I was hoping some of you more experienced users could help. Here is what we are dealing with:

MySql 5.7 Tables:
Qt Code:
  1. DESCRIBE games;
  2. +-------+------------------+------+-----+---------+----------------+
  3. | Field | Type | Null | Key | Default | Extra |
  4. +-------+------------------+------+-----+---------+----------------+
  5. | name | varchar(16) | NO | UNI | NULL | |
  6. | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
  7. +-------+------------------+------+-----+---------+----------------+
  8.  
  9. DESCRIBE drawings;
  10. +---------+------------------+------+-----+---------+----------------+
  11. | Field | Type | Null | Key | Default | Extra |
  12. +---------+------------------+------+-----+---------+----------------+
  13. | date | date | NO | | NULL | |
  14. | game_id | int(11) | NO | | NULL | |
  15. | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
  16. +---------+------------------+------+-----+---------+----------------+
To copy to clipboard, switch view to plain text mode 

C++
Qt Code:
  1. Game::Game(QTabWidget *parent, QString name) :
  2. QTabWidget(parent),
  3. ui(new Ui::Game)
  4. {
  5. this->db = QSqlDatabase::database("LC");
  6.  
  7. this->dbGames = new QSqlRelationalTableModel(this, db);
  8. this->dbDrawings = new QSqlRelationalTableModel(this ,db);
  9. this->dbRecords = new QSqlRelationalTableModel(this, db);
  10. this->dbRules = new QSqlRelationalTableModel(this, db);
  11. this->dbTypes = new QSqlRelationalTableModel(this, db);
  12.  
  13. this->dbGames->setTable("games");
  14. this->dbDrawings->setTable("drawings");
  15. this->dbRecords->setTable("records");
  16. this->dbRules->setTable("rules");
  17. this->dbTypes->setTable("types");
  18.  
  19. this->dbGames->setEditStrategy(QSqlTableModel::OnFieldChange);
  20. this->dbDrawings->setEditStrategy(QSqlTableModel::OnFieldChange);
  21. this->dbRecords->setEditStrategy(QSqlTableModel::OnFieldChange);
  22. this->dbRules->setEditStrategy(QSqlTableModel::OnFieldChange);
  23. this->dbTypes->setEditStrategy(QSqlTableModel::OnFieldChange);
  24.  
  25. this->dbDrawings->setRelation(this->dbDrawings->fieldIndex("game_id"), QSqlRelation("games", "id", "name"));
  26. this->dbRecords->setRelation(this->dbRecords->fieldIndex("drawing_id"), QSqlRelation("drawings", "id", "date"));
  27. this->dbRecords->setRelation(this->dbRecords->fieldIndex("type_id"), QSqlRelation("types", "id", "type"));
  28. this->dbRules->setRelation(this->dbRules->fieldIndex("type_id"), QSqlRelation("types", "id", "type"));
  29. this->dbRules->setRelation(this->dbRules->fieldIndex("game_id"), QSqlRelation("games", "id", "name"));
  30.  
  31. this->dbGames->select();
  32. this->dbDrawings->select();
  33. this->dbRecords->select();
  34. this->dbRules->select();
  35. this->dbTypes->select();
To copy to clipboard, switch view to plain text mode 

and later in the same class:
Qt Code:
  1. int Game::dbaddDrawing(QString dateString)
  2. {
  3. this->dbDrawings->setFilter("");
  4. this->dbDrawings->select();
  5.  
  6. QDate recordDate = QDate::fromString(dateString, this->dateFormat);
  7.  
  8. QSqlRecord drawing = this->dbDrawings->record();
  9.  
  10. drawing.setValue(this->dbDrawings->fieldIndex("date"), recordDate);
  11. drawing.setValue(this->dbDrawings->fieldIndex("name"), QVariant(this->gameName));
  12. drawing.setGenerated(this->dbDrawings->fieldIndex("id"), false);
  13.  
  14. if (!this->dbDrawings->insertRecord(-1, drawing)) //this seems to be where the problem is.
  15. {
  16. console("Drawing Input failure!");
  17. }
  18.  
  19. int returnVal = this->dbDrawings->query().lastInsertId().toInt();
  20.  
  21. return returnVal;
  22. }
To copy to clipboard, switch view to plain text mode 

If I setValue for game_id instead of the relational tables show field (name), the outcome does not change.

My biggest thought has been to look at the insert query and see if that gives hints to where the failure is, but looking at
Qt Code:
  1. this->dbDrawings->query().lastQuery();
To copy to clipboard, switch view to plain text mode 
it always seems to show select queries and never the insert. How can I look at the insert query? is it not showing the insert query because it is never passed? Recommendations for how I can check?

Also, in the docs for QSqlRelationalTableModel it says "If you use a read-write QSqlRelationalTableModel, you probably..." That first part about read-write, what is the deal with that? Is that in reference to the permissions of the db user on the db, or is there a property that I am not seeing in the class that sets permissions?

**Deep breath** I have been at this for a couple of weeks now, while I can operate the database in QSqlTableModel's I can not seem to insert to it's relational counterpart, and I am out of ideas.

Please remember that I am very new (less than a year) to Qt and C++, and not very proficient in MySQL, so please be kind. Any help is greatly appreciated.

THANKS!