How to Handle Incompatible Foreign Key Types in DM Data Synchronization?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: DM同步数据,外键类型不兼容怎么处理?

| username: 莫何者也

The foreign key type is varchar(32), and the referenced type is char(32). Don’t ask me why the original table is like this;
Using DM to synchronize data, it reports an error saying they are incompatible;
How to handle this? I deleted all the foreign keys in the original table, but the task still reports an error; it should be that DM has already pulled the information and will not pull the modified table structure again.

| username: 有猫万事足 | Original post link

You can use dmctl binlog-schema to modify the mapping of the table structure.

| username: wangkk2024 | Original post link

Remove the foreign key and resynchronize.

| username: 健康的腰间盘 | Original post link

Try synchronizing in batches according to the ER diagram of the foreign key table.

| username: 不想干活 | Original post link

I think you can try restarting and then syncing again.

| username: yytest | Original post link

When using the DM (Data Migration) tool for data synchronization, if you encounter issues with incompatible foreign key types, it is indeed because DM has recorded the original table structure. Even if the table structure is modified later, DM will not automatically update this information. To resolve this issue, you can follow these steps:

  1. Stop the DM task: First, ensure that you have stopped the ongoing data synchronization task.
  2. Clean up metadata: DM will create a database named dm_meta in the upstream MySQL instance to store metadata for synchronization tasks. You need to manually clean up this metadata so that DM can re-read the table structure.
| username: 小于同学 | Original post link

Then it can only be removed.

| username: Hacker007 | Original post link

DM’s synchronization support for foreign keys is not very good. If it really can’t be handled, get the latest binlog and create a new task to resynchronize.

| username: kelvin | Original post link

After removing the foreign key, you can try resetting the data migration task.

When an exception occurs during the data migration process and it cannot be recovered, you need to reset the data migration task and re-migrate the data:

  1. Use stop-task to stop the abnormal data migration task.
  2. Clean up the data that has been migrated downstream.
  3. Choose one of the following two methods to restart the data migration task:
    • Modify the task configuration file to specify a new task name, then use start-task {task-config-file} to restart the migration task.
    • Use start-task --remove-meta {task-config-file} to restart the data migration task.
| username: zhaokede | Original post link

Remove foreign keys, foreign keys are not supported during import.

| username: 莫何者也 | Original post link

In the end, it was done this way, but you need to delete dm_meta.

| username: 莫何者也 | Original post link

Basically, this is how it’s done: initially, stop the task, delete the already synchronized data, and then create a new task (with a different name, otherwise it will still report an error). Later, I found out that deleting dm_meta should allow a complete restart. Additionally, at the beginning, the foreign keys were not completely cleaned up, and during the process, I encountered the issue again, so I had to create a new task.