Bug #32972 WB doesn't handle default-Value for columns
Submitted: 4 Dec 2007 18:06 Modified: 10 Jul 2008 12:55
Reporter: Johannes Taxacher Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench Severity:S4 (Feature request)
Version: OS:Any
Assigned to: Maksym Yehorov CPU Architecture:Any

[4 Dec 2007 18:06] Johannes Taxacher
Description:
if one makes a table-colum (which has NULL specified as default value) PK then WB should take care of the default-value (removing NULL as default when PK is not AI, or adding NULL if it is not specified and the col has the AI-flag).

when making a column PK and this col. has NULL as default value, this default-val isn't changed. when this table gets synchronized back to the db wb creates a statement like this:

ALTER TABLE `test_defhan`.`table1` CHANGE COLUMN `id_table1` `id_table1` INT(11) NOT NULL DEFAULT NULL, ...

which leads to:
Error 1067: Invalid default value for 'id_table1'

How to repeat:
Reverse Engineer this model:

CREATE DATABASE IF NOT EXISTS `test_defhan` DEFAULT CHARACTER SET latin1 ;
USE `test_defhan`;
CREATE  TABLE IF NOT EXISTS `test_defhan`.`table1` (`id_table1` INT);

The imported table doesn't have a PK. Correct this issue by doubleclicking the id_table1-column in table editor (on the little diamonds-icon).
now select Database->Synchronize... and go through the wizard (all defaults) when it comes to execute the ALTER statements an error appears because of the "... INT(11) NOT NULL DEFULT NULL "

Suggested fix:
make wb take care of the default-value column for PK columns
[14 Apr 2008 15:53] Alfredo Kojima
This should be implemented as a validation for columns, looking for
 NOT NULL DEFAULT NULL columns.
[21 May 2008 17:07] Johannes Taxacher
fixed (tested in bzr rev 3106)
[10 Jul 2008 12:55] Tony Bedford
An entry has been added to the 5.0.21 changelog:

When making a column a primary key and this column has NULL as default value, this default value is not changed. When the table gets synchronized back to the database Workbench creates a statement such as: 

ALTER TABLE `test_defhan`.`table1` CHANGE COLUMN `id_table1` `id_table1` INT(11) NOT NULL
DEFAULT NULL, ...

This leads to an error: 

Error 1067: Invalid default value for 'id_table1'