{"record":{"id":"8a946ffb3b9cc73e","repo":"MyCATApache/Mycat-Server","slug":"parent-relevant-column-can-t-be-updated","errorCode":null,"errorMessage":"Parent relevant column can't be updated ->","messagePattern":"Parent relevant column can't be updated ->","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/parser/druid/impl/DruidUpdateParser.java","lineNumber":241,"sourceCode":"                if (column.contains(StringUtil.TABLE_COLUMN_SEPARATOR)) {\n                    column = column.substring(column.indexOf(\".\") + 1).trim().toUpperCase();\n                }\n                if (partitionColumn != null && partitionColumn.equals(column)) {\n                    boolean canUpdate;\n                    canUpdate = ((update.getWhere() != null) && shardColCanBeUpdated(update.getWhere(),\n                            partitionColumn, item.getValue(), false));\n\n                    if (!canUpdate) {\n                        String msg = \"Sharding column can't be updated \" + tableName + \"->\" + partitionColumn;\n                        LOGGER.warn(msg);\n                        throw new SQLNonTransientException(msg);\n                    }\n                }\n                if (hasParent) {\n                    if (column.equals(joinKey)) {\n                        String msg = \"Parent relevant column can't be updated \" + tableName + \"->\" + joinKey;\n                        LOGGER.warn(msg);\n                        throw new SQLNonTransientException(msg);\n                    }\n                    rrs.setCacheAble(true);\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":223,"sourceCodeEnd":249,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/druid/impl/DruidUpdateParser.java#L223-L249","documentation":"For child tables in an ER (parent-child) sharding relationship, the join key column that links to the parent cannot be updated — doing so would move the child row to a different shard than its parent. Mycat throws this when the SET clause targets the table's joinKey while the schema declares a parent table (hasParent).","triggerScenarios":"UPDATE on an ER child table (TableConfig with parentTable configured) where a SET item names the joinKey column, detected in confirmShardColumnNotUpdated via column.equals(joinKey).","commonSituations":"Re-parenting a child row (e.g. changing order_id on order_item) through UPDATE; schema configs where the join key was chosen as a mutable business field; ORM save() rewrites that include the FK in SET.","solutions":["Remove the join key from the SET clause if the parent link is unchanged","Delete and re-insert the child row to move it to a different parent","Redesign the schema so the ER join key is immutable (use a surrogate PK for parent links)","Update parent linkage in the application with coordinated delete+insert"],"exampleFix":"// before\nUPDATE order_item SET order_id=200 WHERE item_id=1;\n// after\nDELETE FROM order_item WHERE item_id=1;\nINSERT INTO order_item(item_id,order_id,...) VALUES(1,200,...);","handlingStrategy":"validation","validationCode":"TableConfig tc = schema.getTables().get(tableName);\nif (tc != null && tc.getParentTC() != null && setColumns.contains(tc.getJoinKey())) {\n    throw new IllegalArgumentException(\"ER join key \" + tc.getJoinKey() + \" is immutable\");\n}","typeGuard":null,"tryCatchPattern":"try { router.route(...) } catch (SQLNonTransientException e) { if (e.getMessage().startsWith(\"Parent relevant column can't be updated\")) { performDeleteInsertInstead(); } }","preventionTips":["Choose immutable join keys when designing ER shard relationships","Exclude join keys from ORM dirty-check SET lists","Move child rows via delete+insert, not UPDATE of the FK"],"tags":["mysql","sharding","er-join-key"],"backgroundTag":"unsupported-operation","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}