Bug #34897 Syncronize creates an invalid alter script when the user adds a new foreign key
Submitted: 27 Feb 2008 17:33 Modified: 15 Mar 2008 12:27
Reporter: Vlad Untu Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench Severity:S3 (Non-critical)
Version:5.0.14 OS:Any
Assigned to: Vladimir Kolesnikov CPU Architecture:Any

[27 Feb 2008 17:33] Vlad Untu
Description:
The Database -> Syncronize does not produce the correct alter script when foreign keys are added.

How to repeat:
1. Create the following schema:

CREATE SCHEMA IF NOT EXISTS `new_schema1` ;
USE `new_schema1`;

-- -----------------------------------------------------
-- Table `new_schema1`.`table`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `new_schema1`.`table` (
  `id_table` INT NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id_table`) )
ENGINE=InnoDB;

-- -----------------------------------------------------
-- Table `new_schema1`.`child_table`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `new_schema1`.`child_table` (
  `id_child_table` INT NOT NULL AUTO_INCREMENT ,
  `id_table` INT NULL ,
  `child_name` VARCHAR(45) NULL ,
  PRIMARY KEY (`id_child_table`) )
ENGINE=InnoDB;

2. Reverse engineer the schema into workbench.
3. Add Diagram
4. Drag table and child_table into the diagram.
5. Add one 1:n Identifying Relationship between child_table and table.
6. Save.
7. Database -> Syncronize
8. Examine the output script:

ALTER TABLE `new_schema1`.`child_table` ADD COLUMN `id_table1` INT(11) NOT NULL  AFTER `child_name` ADD CONSTRAINT `fk_child_table_id_table`
  FOREIGN KEY (`id_table` )
  REFERENCES `new_schema1`.`table` (`id_table` )
  ON DELETE NO ACTION
  ON UPDATE NO >>>>>ACTIONADD<<<<< INDEX fk_child_table_table (`id_table` ASC) ;

there is no space or enter between ACTION and ADD.

Suggested fix:
Add space or enter between ACTION and ADD.
[27 Feb 2008 17:39] Vlad Untu
typo
[27 Feb 2008 19:59] Valeriy Kravchuk
Thank you for a bug report.
[6 Mar 2008 15:22] Gert van de Venis
I was having the same problem, i only couldn't reproduce the issue. I also noticed that every alter script you generate has the same problem. Even if you use the Export>Forward Engineer ALTER Script function. This thus also occurs in the OSS edition of Workbench! 

Another little point that could be improved on could be to make the generated Alter script in the Sync Dialog editable, so it can be manually corrected/altered befor execution!
[13 Mar 2008 10:18] Johannes Taxacher
fixed in 2728
[15 Mar 2008 12:27] MC Brown
A note has been added to the 5.15 changelog: 

Incorrect ALTER statements are created during the synchronization process if you add foreign keys to an existing or imported model.