Bug #74558 Table Editor: Ticking NN does not clear a NULL
Submitted: 24 Oct 2014 22:09 Modified: 13 May 2016 2:47
Reporter: Craig Macdonald Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench Severity:S3 (Non-critical)
Version:6.2 OS:Any (Mac, Windows)
Assigned to: CPU Architecture:Any
Tags: TableEditor

[24 Oct 2014 22:09] Craig Macdonald
Description:
In the Table Editor

If a column has NN checked, and NN is then unticked, then a default NULL value is added automatically added to the CREATE TABLE statement, when the Apply button is clicked. The column then shows a default value of NULL in the Table Editor.

If the column has the NN tickbox un-checked, then:
 - if NN is then checked, the default NULL value is removed (this is inline with above)
 - however, if PK is then checked, the default NULL value is /not/ removed, even though NN is now also checked. This is a bug.

How to repeat:
Add columns to a table with some columns. Make one allow NULLs. Click Apply.

Check the PK tickbox for that column. Click Apply. 

Resulting SQL Is:
{{{
ALTER TABLE `workbenchtest`.`new_table` 
CHANGE COLUMN `new_tablecol` `new_tablecol` INT(11) NOT NULL DEFAULT NULL ,
ADD PRIMARY KEY (`new_tablecol`);
}}}

Error is:
{{{
ERROR 1067: Invalid default value for 'new_tablecol'
SQL Statement:
ALTER TABLE `workbenchtest`.`new_table` 
CHANGE COLUMN `new_tablecol` `new_tablecol` INT(11) NOT NULL DEFAULT NULL ,
ADD PRIMARY KEY (`new_tablecol`)
}}}

Suggested fix:
In backend/wbpublic/grtdb/editor_table.cpp, in TableColumnsListBE::set_field(), some of the code from "case IsNotNull" branch should be copied up to the  "if (value != 0)" part of the "case IsPK:" branch.
[24 Oct 2014 22:10] Craig Macdonald
screen1

Attachment: screen1.png (image/png, text), 418.09 KiB.

[24 Oct 2014 22:10] Craig Macdonald
screen2

Attachment: screen2.png (image/png, text), 419.63 KiB.

[24 Oct 2014 22:10] Craig Macdonald
Please remove 74515_screen1, I uploaded the wrong file
[24 Oct 2014 23:18] MySQL Verification Team
Error Message

Attachment: null.png (image/png, text), 64.11 KiB.

[24 Oct 2014 23:19] MySQL Verification Team
Thank you for the bug report.
[27 Oct 2014 9:04] Craig Macdonald
corrected version tag
[13 May 2016 2:47] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Workbench 6.3.7 release, and here's the changelog entry:

In the Table Editor, if a column has NN checked, and NN is then unchecked,
then a default NULL value is automatically added to the CREATE TABLE
statement when Apply is clicked. The column then shows a default value of
NULL in the Table Editor.

Thank you for the bug report.