{"record":{"id":"490b877415327b8a","repo":"YunaiV/yudao-cloud","slug":"f-col-type-name-ddl-tab","errorCode":null,"errorMessage":"f\"未支持的类型: '{col['type']}' (列: {name}, 表: {ddl['table_name']})\"","messagePattern":"f\"未支持的类型: '(.+?)' \\(列: (.+?), 表: (.+?)\\)\"","errorType":"console","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sql/tools/convertor.py","lineNumber":447,"sourceCode":"        if type in (\"blob\", \"mediumblob\", \"longblob\"):\n            return \"bytea\"\n        if type == \"decimal\":\n            return (\n                f\"numeric({','.join(str(s) for s in size)})\" if size and len(size) else \"numeric\"\n            )\n\n    def gen_create(self, ddl: Dict) -> str:\n        \"\"\"生成 create\"\"\"\n\n        def _generate_column(col):\n            name = col[\"name\"].lower()\n            if name == \"deleted\":\n                return \"deleted int2 NOT NULL DEFAULT 0\"\n\n            type = col[\"type\"].lower()\n            full_type = self.translate_type(type, col[\"size\"])\n            if full_type is None:\n                raise NotImplementedError(\n                    f\"未支持的类型: '{col['type']}' (列: {name}, 表: {ddl['table_name']})\"\n                )\n            nullable = \"NULL\" if col[\"nullable\"] else \"NOT NULL\"\n            default = f\"DEFAULT {col['default']}\" if col[\"default\"] is not None else \"\"\n            return f\"{self.escape_column_name(name)} {full_type} {nullable} {default}\"\n\n        table_name = ddl[\"table_name\"].lower()\n        columns = [f\"{_generate_column(col).strip()}\" for col in ddl[\"columns\"]]\n        filed_def_list = \",\\n  \".join(columns)\n        script = f\"\"\"-- ----------------------------\n-- Table structure for {table_name}\n-- ----------------------------\nDROP TABLE IF EXISTS {table_name};\nCREATE TABLE {table_name} (\n    {filed_def_list}\n);\"\"\"\n\n        return script","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/YunaiV/yudao-cloud/blob/477be9dd49ab7223a972a6abdff0684d6423dec3/sql/tools/convertor.py#L429-L465","documentation":"Raised inside gen_create -> _generate_column in sql/tools/convertor.py when translate_type(type, size) returns None for the column's MySQL type. Each convertor's translate_type is a whitelist of if-comparisons (varchar, int, bigint, tinyint, datetime, json, double, bit, text, blob, decimal, ...); any MySQL type not on the list falls off the end, returning None, and _generate_column raises NotImplementedError naming the type, column, and table. It means the DDL convertor simply has no mapping rule for that column type yet.","triggerScenarios":"Running the convertor CLI on a MySQL DDL dump that contains a column type not in the whitelist, e.g. ENUM('a','b'), SET, FLOAT, MEDIUMINT, CHAR(n), YEAR, GEOMETRY, VARBINARY, or a vendor-specific type. The error fires per-table while generating CREATE TABLE statements, and includes the offending column name and table name.","commonSituations":"Converting a hand-written or legacy schema that uses ENUM/SET instead of lookup tables; converting MySQL 8 dumps with newer types; a type spelled differently in the dump than the whitelist expects (the comparison is exact after .lower()); processing third-party application schemas (WordPress, etc.) with unusual types.","solutions":["Read the message: it names the exact column type, column, and table — open the source DDL and confirm the raw type string (the code compares type.lower() against exact literals).","Add a mapping branch to translate_type in the convertor class you are using (line 402 area for the PostgreSQL-family convertor) — e.g. `if type == \"float\": return \"float4\"`, `if type == \"enum\": return \"varchar(255)\"`, `if type == \"char\": return f\"char({size})\"`.","If the type is irrelevant (audit/legacy column), strip or edit that column from the input SQL dump and re-run.","For one-off conversions, pre-normalize the DDL with sed to rewrite the unsupported type to a supported one before feeding it to the convertor."],"exampleFix":"# before — translate_type has no branch for 'float'/'enum', so it returns None and gen_create raises NotImplementedError\n\n# after — add branches to translate_type (sql/tools/convertor.py, PostgreSQL-family convertor)\nif type == \"float\":\n    return \"float4\"\nif type == \"enum\":\n    return \"varchar(255)\"\nif type == \"char\":\n    return f\"char({size})\" if size else \"char\"","handlingStrategy":"type-guard","validationCode":"SUPPORTED_TYPES = {\n    \"varchar\", \"int\", \"int unsigned\", \"int unsigned zerofill\", \"bigint\", \"bigint unsigned\",\n    \"tinyint\", \"smallint\", \"tinyint unsigned\", \"datetime\", \"timestamp null\", \"date\",\n    \"json\", \"double\", \"timestamp\", \"bit\", \"text\", \"longtext\", \"blob\", \"mediumblob\",\n    \"longblob\", \"decimal\",\n}\n\n# scan the parsed DDL before generating\ndef check_columns(ddl):\n    bad = [c for c in ddl[\"columns\"] if c[\"type\"].lower() not in SUPPORTED_TYPES and c[\"name\"].lower() != \"deleted\"]\n    if bad:\n        raise ValueError(f\"Unsupported types in table {ddl['table_name']}: {[(c['name'], c['type']) for c in bad]}\")","typeGuard":"def is_supported_type(col: Dict) -> bool:\n    \"\"\"True if convertor.translate_type maps this column type (never returns None).\"\"\"\n    if col[\"name\"].lower() == \"deleted\":\n        return True\n    return convertor.translate_type(col[\"type\"].lower(), col.get(\"size\")) is not None","tryCatchPattern":"try:\n    script = convertor.gen_create(ddl)\nexcept NotImplementedError as e:\n    # e.message names the type, column, and table: add a mapping branch to\n    # translate_type, or normalize/skip that column, then re-run\n    log.warning(\"skipping table %s: %s\", ddl[\"table_name\"], e)\n    # decide: fix the mapping (preferred) or skip the table and report it","preventionTips":["Run a pre-flight scan of the DDL dump for column types before converting; flag anything outside the whitelist.","Prefer plain types in source schemas (varchar over enum/set) when you control the schema.","When adding a mapping, also add a unit DDL fixture so regressions in translate_type are caught.","Keep a checklist of types each convertor subclass supports; they are not identical across targets."],"tags":["sql","ddl-conversion","mysql","postgresql","not-implemented","python","schema"],"backgroundTag":null,"analyzedSha":"477be9dd49ab7223a972a6abdff0684d6423dec3","analyzedAt":"2026-08-14T13:35:31.121Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}