Skip to content

Copy To: fails on foreign key constraints (no FK_CHECKS disable, alphabetical table order) + very slow compare phase #3858

Closed

Description

@MrWeb

Environment

  • TablePro version: 0.83.0 (830099)
  • macOS: 27.0.1

Problem

Copy To from a remote MySQL database to a local one (Structure and data, Replace existing, 100 of 100 tables) fails on foreign keys:

buildings: [1452] Cannot add or update a child row: a foreign key constraint fails
(`regest`.`buildings`, CONSTRAINT `buildings_residence_id_foreign`
FOREIGN KEY (`residence_id`) REFERENCES `estates` (`id`) ON DELETE CASCADE)
(SQLSTATE: 23000)

Result: "Copy finished with errors - 99 objects, 178 rows". The structure is created, almost no data is copied.

Cause

The structure phase already turned foreign key checks off, but the data phase did not. Tables are copied in name order with checks on, so a child written before its parent fails.

Fixed

#3859 runs the data phase with the target's foreign key checks off, on the connection that writes the rows, and restores them before the connection returns to the pool (same idea as mysqldump). It uses each driver's own disable and enable statements. Covered by a test that fails without the change.

Not tried against a live MySQL server yet.

Still open

  • The compare phase is very slow on a database of this size.
  • Tables are not ordered by foreign key dependency (parents first).
  • No option to continue on error instead of stopping the whole data copy.
  • Optional checkbox "Disable foreign key checks during copy".

Related feature request

A one-click "Copy to..." from remote to local, as other clients offer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions