Migrating a MYSQL DB from inno no cluster to ndb cluster

32 Views Asked by At

If we are migrating a MYSQL DB from inno no cluster to ndb cluster, and we have a column of type BLOB for example with cascade on delete or update. Converting to ndb cluster will result in an error since this syntax is not allowed (limitation). What is the alternative and how to fix our script in this case?

1

There are 1 best solutions below

0
Bill Karwin On

As you discovered, NDB does not fully support cascading foreign keys, because of its implementation.

The details are documented here, for other readers who want to know: https://dev.mysql.com/doc/mysql-cluster-excerpt/8.3/en/mysql-cluster-limitations-syntax.html

There are several workarounds:

  • Perform cascading deletes in triggers.

  • Perform cascading deletes in application code.

  • For cascading updates, all you can do is refrain from defining foreign key constraints at all.

You can't cascade primary key updates using triggers or application code, because you end up with a chicken-and-egg problem. You can't change the primary key of the parent table first, because child rows depend on its value, and you can't change child rows first because the new value doesn't exist in the parent table yet.

So the workaround for updates is to forget about using the foreign key constraint. Then you can make changes to both tables in a transaction. It's up to you to make sure referential integrity is satsified by the end of your transaction, because without a constraint the database can't enforce it.