The replicator should detect that the column already exists in ClickHouse and only update its definition (or ignore the change if unsupported), rather than attempting to add the column again.
[dbrepl x_crm 2025-12-09 04:44:03,844 ERROR] unhandled exception
Traceback (most recent call last):
File "/app/mysql_ch_replicator/db_replicator.py", line 216, in run
self.run_realtime_replication()
File "/app/mysql_ch_replicator/db_replicator.py", line 260, in run_realtime_replication
self.realtime_replicator.run_realtime_replication()
File "/app/mysql_ch_replicator/db_replicator_realtime.py", line 73, in run_realtime_replication
self.handle_event(event)
File "/app/mysql_ch_replicator/db_replicator_realtime.py", line 94, in handle_event
event_handlers[event.event_type](event)
File "/app/mysql_ch_replicator/db_replicator_realtime.py", line 185, in handle_query_event
self.handle_alter_query(query, event.db_name)
File "/app/mysql_ch_replicator/db_replicator_realtime.py", line 199, in handle_alter_query
self.replicator.converter.convert_alter_query(query, db_name)
File "/app/mysql_ch_replicator/converter.py", line 696, in convert_alter_query
self.__convert_alter_table_add_column(db_name, table_name, tokens)
File "/app/mysql_ch_replicator/converter.py", line 851, in __convert_alter_table_add_column
self.db_replicator.clickhouse_api.execute_command(query)
File "/app/mysql_ch_replicator/clickhouse_api.py", line 124, in execute_command
self.client.command(query)
File "/usr/local/lib/python3.12/site-packages/clickhouse_connect/driver/httpclient.py", line 351, in command
response = self._raw_request(payload, params, headers, method, fields=fields, server_wait=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/clickhouse_connect/driver/httpclient.py", line 462, in _raw_request
self._error_handler(response)
File "/usr/local/lib/python3.12/site-packages/clickhouse_connect/driver/httpclient.py", line 385, in _error_handler
raise OperationalError(err_str) if retried else DatabaseError(err_str) from None
clickhouse_connect.driver.exceptions.DatabaseError: HTTPDriver for http://clickhouse:8123 received ClickHouse error code 15
Code: 15. DB::Exception: Cannot add column `sale_type_list`: column with this name already exists. (DUPLICATE_COLUMN) (version 25.9.2.1 (official build))
Bug Description
After adding a new column
sale_type_listin MySQL (initially defined asNULL), I later altered it to beNOT NULL. Since then, mysql_ch_replicator consistently throws errors during real-time replication. The error indicates that ClickHouse cannot add the column because it already exists. It seems the replicator is attempting to runALTER TABLE ADD COLUMNagain instead of handling the column modification properly.Steps to Reproduce
sale_type_listin a MySQL table, initially allowingNULL.NOT NULLin MySQL.Expected Behavior
The replicator should detect that the column already exists in ClickHouse and only update its definition (or ignore the change if unsupported), rather than attempting to add the column again.
Actual Behavior
Environment