Bug report #13089
DBManager edit table dialog bug on notNull values
|Affected QGIS version:||2.10.0||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||Yes||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||21156|
I 've found a bug in the edit table dialog of DBManager.
Whenever you try to edit a field, the notNull attribute is never retrieved (the checkBox "can be Null" is always checked even if the field has a NOT NULL constraint).
I think that the problem comes from the TableFieldsModel class in db_plugins/data_model.py.
The getObject method which is called when you click on the "Edit column" button always returned a False value because of the following line:
fld.notNull = self.data(self.index(row, 2), Qt.CheckStateRole) == Qt.Unchecked
Actually, the data in column 2 (notNull) doesn't have a Qt.CheckStateRole value (None), so the test is always false.
Furthermore, the notNull column should be a checkboxed column and it only appears as a standard column (with True or False strings).
By adding the two following lines in the append method of the TableFieldsModel class from db_plugins/data_model.py, I think that the bug is fixed.
... class TableFieldsModel(SimpleTableModel): ... def append(self, fld): data = [fld.name, fld.type2String(), not fld.notNull, fld.default2String()] self.appendRow(self.rowFromData(data)) row = self.rowCount() - 1 self.setData(self.index(row, 0), fld, Qt.UserRole) self.setData(self.index(row, 1), fld.primaryKey, Qt.UserRole) self.setData(self.index(row, 2), not fld.notNull, Qt.CheckStateRole) # set check state self.setData(self.index(row, 2), None, Qt.DisplayRole) # don't show the value ...
Whith those two lines, the edit field dialog finds the good value for notNull variable and user can check the box directly inside the column.
Thanks for fixing this...