Bug #121737 MySQL Workbench – Synchronization defects involving table renames, foreign keys, and potential data loss
Description:
MySQL Workbench's Synchronize Model operation has repeatedly generated inconsistent SQL when renaming tables that contain foreign keys.
The generated script can successfully rename a table and subsequently execute additional ALTER TABLE statements against its former name. This results in Error 1146 after part of the synchronization has already been applied.
After this partial failure, Workbench may retain outdated synchronization metadata, causing the same table to appear as two independent objects. Subsequent synchronization attempts can generate CREATE TABLE and DROP TABLE statements against the same existing table.
A separate incident involving a column-name change generated DROP COLUMN and ADD COLUMN operations instead of a data-preserving rename, introducing another potential data-loss risk.
How to repeat:
1.Create a table containing a foreign key and synchronize the EER model with an existing MySQL database.
2.Rename the table in the EER model.
3.Run Database → Synchronize Model.
4.Review and execute the generated SQL.
5.Observe that the rename may succeed, but subsequent foreign-key operations still reference the previous table name.
6.Attempt synchronization again after the partial failure.
@Observed results
Incident A – Table rename and Error 1146
Original name: asistencia_operadores
New name: asistencias_operadores
The synchronization reported:
ERROR 1146:
Table 'cualli.asistencia_operadores' doesn't exist
244 statements succeeded, 1 failed
Failing statement:
ALTER TABLE `cualli`.`asistencia_operadores`
DROP FOREIGN KEY `fk_asistencia_operadores_tipo_id`;
Database inspection confirmed that the table already existed under its new name.
The MWB model still contained:
name = asistencias_operadores
oldName = asistencia_operadores
lastKnownDBNames = asistencia_operadores
Incident B – Rename followed by DDL against the old name
Original name: postprocesado_ftecnica
New name: preprocesado_ftecnica
Workbench generated:
ALTER TABLE `cualli`.`postprocesado_ftecnica`
CHANGE COLUMN `postprocesado_id`
`preprocesado` BIGINT(20) NOT NULL,
RENAME TO `cualli`.`preprocesado_ftecnica`;
Later in the same script:
ALTER TABLE `cualli`.`postprocesado_ftecnica`
ADD CONSTRAINT ...
The second operation references a table name that no longer exists after the rename.
Incident C – Dangerous synchronization after a partial failure
Workbench displayed:
preprocesado → N/A
N/A → preprocesado
The generated SQL included:
CREATE TABLE IF NOT EXISTS `cualli`.`preprocesado` (...);
DROP TABLE IF EXISTS `cualli`.`preprocesado`;
If executed against an existing table, the CREATE statement would be skipped and the DROP statement could delete the actual table and its records.
Incident D – Potentially destructive column synchronization
When reconciling the preprocesado_ftecnica model with the database, Workbench generated:
ALTER TABLE `cualli`.`preprocesado_ftecnica`
DROP COLUMN `preprocesado_id`,
ADD COLUMN `preprocesado` BIGINT(20) NOT NULL FIRST;
This operation would discard existing column values rather than preserve them through a rename.
The script was inspected before execution, and this destructive operation was not applied.
@Expected behavior
Subsequent DDL statements must reference the new table name after a rename.
Synchronization should preserve table identity following a partially completed operation.
Existing tables must not be proposed for both creation and deletion because of stale rename metadata.
Column rename operations should preserve existing values when a rename is intended.
Potentially destructive transformations should receive explicit warnings before execution.
@ Root-cause observations
Investigation of the .mwb package identified outdated metadata in document.mwb.xml:
db.mysql.Table.oldName
db.mgmt.SyncProfile.lastKnownDBNames
After confirming that the database already contained the renamed table, updating these two references in a copied MWB restored the correct table matching.
This repair was successfully reproduced across multiple incidents.
The complete cause of the column-mapping behavior has not yet been established.
@ Related reports
MySQL Bug #87684 – On a table rename, Workbench generates additional ALTER SQL for the wrong table name.
MySQL Bug #77633 – Multiple changes to a table in Workbench do not apply.
The reported behavior closely resembles these existing issues. This report provides additional evidence of persistent synchronization metadata inconsistencies and potential data loss.
@ Requested improvements
Please investigate dependency-aware DDL generation for table renames, synchronization metadata reconciliation after partial failures, and safety validation for destructive DROP/CREATE operations.
In particular, Synchronize Model should detect and prevent execution when its generated script contains contradictory operations against the same persistent database object.
@ Available evidence
Original and repaired .mwb model files.
Complete synchronization SQL generated during the incidents.
Screenshots showing incorrect table matching.
Error 1146 execution logs.
Repeated successful restoration of table matching after synchronization metadata repair.
A minimal reproducible model and sanitized SQL can be supplied if required.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.056 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: MySQL Workbench's Synchronize Model operation has repeatedly generated inconsistent SQL when renaming tables that contain foreign keys. The generated script can successfully rename a table and subsequently execute additional ALTER TABLE statements against its former name. This results in Error 1146 after part of the synchronization has already been applied. After this partial failure, Workbench may retain outdated synchronization metadata, causing the same table to appear as two independent objects. Subsequent synchronization attempts can generate CREATE TABLE and DROP TABLE statements against the same existing table. A separate incident involving a column-name change generated DROP COLUMN and ADD COLUMN operations instead of a data-preserving rename, introducing another potential data-loss risk. How to repeat: 1.Create a table containing a foreign key and synchronize the EER model with an existing MySQL database. 2.Rename the table in the EER model. 3.Run Database → Synchronize Model. 4.Review and execute the generated SQL. 5.Observe that the rename may succeed, but subsequent foreign-key operations still reference the previous table name. 6.Attempt synchronization again after the partial failure. @Observed results Incident A – Table rename and Error 1146 Original name: asistencia_operadores New name: asistencias_operadores The synchronization reported: ERROR 1146: Table 'cualli.asistencia_operadores' doesn't exist 244 statements succeeded, 1 failed Failing statement: ALTER TABLE `cualli`.`asistencia_operadores` DROP FOREIGN KEY `fk_asistencia_operadores_tipo_id`; Database inspection confirmed that the table already existed under its new name. The MWB model still contained: name = asistencias_operadores oldName = asistencia_operadores lastKnownDBNames = asistencia_operadores Incident B – Rename followed by DDL against the old name Original name: postprocesado_ftecnica New name: preprocesado_ftecnica Workbench generated: ALTER TABLE `cualli`.`postprocesado_ftecnica` CHANGE COLUMN `postprocesado_id` `preprocesado` BIGINT(20) NOT NULL, RENAME TO `cualli`.`preprocesado_ftecnica`; Later in the same script: ALTER TABLE `cualli`.`postprocesado_ftecnica` ADD CONSTRAINT ... The second operation references a table name that no longer exists after the rename. Incident C – Dangerous synchronization after a partial failure Workbench displayed: preprocesado → N/A N/A → preprocesado The generated SQL included: CREATE TABLE IF NOT EXISTS `cualli`.`preprocesado` (...); DROP TABLE IF EXISTS `cualli`.`preprocesado`; If executed against an existing table, the CREATE statement would be skipped and the DROP statement could delete the actual table and its records. Incident D – Potentially destructive column synchronization When reconciling the preprocesado_ftecnica model with the database, Workbench generated: ALTER TABLE `cualli`.`preprocesado_ftecnica` DROP COLUMN `preprocesado_id`, ADD COLUMN `preprocesado` BIGINT(20) NOT NULL FIRST; This operation would discard existing column values rather than preserve them through a rename. The script was inspected before execution, and this destructive operation was not applied. @Expected behavior Subsequent DDL statements must reference the new table name after a rename. Synchronization should preserve table identity following a partially completed operation. Existing tables must not be proposed for both creation and deletion because of stale rename metadata. Column rename operations should preserve existing values when a rename is intended. Potentially destructive transformations should receive explicit warnings before execution. @ Root-cause observations Investigation of the .mwb package identified outdated metadata in document.mwb.xml: db.mysql.Table.oldName db.mgmt.SyncProfile.lastKnownDBNames After confirming that the database already contained the renamed table, updating these two references in a copied MWB restored the correct table matching. This repair was successfully reproduced across multiple incidents. The complete cause of the column-mapping behavior has not yet been established. @ Related reports MySQL Bug #87684 – On a table rename, Workbench generates additional ALTER SQL for the wrong table name. MySQL Bug #77633 – Multiple changes to a table in Workbench do not apply. The reported behavior closely resembles these existing issues. This report provides additional evidence of persistent synchronization metadata inconsistencies and potential data loss. @ Requested improvements Please investigate dependency-aware DDL generation for table renames, synchronization metadata reconciliation after partial failures, and safety validation for destructive DROP/CREATE operations. In particular, Synchronize Model should detect and prevent execution when its generated script contains contradictory operations against the same persistent database object. @ Available evidence Original and repaired .mwb model files. Complete synchronization SQL generated during the incidents. Screenshots showing incorrect table matching. Error 1146 execution logs. Repeated successful restoration of table matching after synchronization metadata repair. A minimal reproducible model and sanitized SQL can be supplied if required.