YunaiV/ruoyi-vue-pro · error · NotImplementedError

未支持的类型: '{col['type']}' (列: {name}, 表: {ddl['table_name']})

Error message

未支持的类型: '{col['type']}' (列: {name}, 表: {ddl['table_name']})

What it means

Raised by _generate_column inside a convertor's gen_create when translate_type returns None for a MySQL column type it does not know how to map. translate_type is a fixed if/elif chain (e.g. varchar→varchar(size), int→int4, json→jsonb, blob→bytea); any type outside that chain (e.g. enum, set, mediumint, year, float, geometry, tinytext, char) yields None and this NotImplementedError fires, naming the offending column and table.

Source

Thrown at sql/tools/convertor.py:447

        if type in ("blob", "mediumblob", "longblob"):
            return "bytea"
        if type == "decimal":
            return (
                f"numeric({','.join(str(s) for s in size)})" if size and len(size) else "numeric"
            )

    def gen_create(self, ddl: Dict) -> str:
        """生成 create"""

        def _generate_column(col):
            name = col["name"].lower()
            if name == "deleted":
                return "deleted int2 NOT NULL DEFAULT 0"

            type = col["type"].lower()
            full_type = self.translate_type(type, col["size"])
            if full_type is None:
                raise NotImplementedError(
                    f"未支持的类型: '{col['type']}' (列: {name}, 表: {ddl['table_name']})"
                )
            nullable = "NULL" if col["nullable"] else "NOT NULL"
            default = f"DEFAULT {col['default']}" if col["default"] is not None else ""
            return f"{self.escape_column_name(name)} {full_type} {nullable} {default}"

        table_name = ddl["table_name"].lower()
        columns = [f"{_generate_column(col).strip()}" for col in ddl["columns"]]
        filed_def_list = ",\n  ".join(columns)
        script = f"""-- ----------------------------
-- Table structure for {table_name}
-- ----------------------------
DROP TABLE IF EXISTS {table_name};
CREATE TABLE {table_name} (
    {filed_def_list}
);"""

        return script

View on GitHub (pinned to 0418084e22)

Solutions

  1. Add a branch to the relevant convertor's translate_type returning the target-dialect equivalent (e.g. enum/set → text or varchar, year → int2, mediumint → int4).
  2. Pre-scan the DDL for types not in the supported set and either rewrite the source column types or extend translate_type before converting.
  3. If the column is disposable, drop or alter it in the source SQL before running the convertor.
  4. Run the convertor dialect whose translate_type already covers your types (the PostgreSQL convertor at line 402 is one reference map).

Example fix

# before — translate_type has no branch for 'enum'
#   → NotImplementedError: 未支持的类型: 'enum' (列: status, 表: t_order)

# after — add a mapping
def translate_type(self, type, size):
    type = type.lower()
    ...
    if type in ("enum", "set"):
        return "varchar"
    if type in ("mediumint", "mediumint unsigned"):
        return "int4"
    if type == "year":
        return "int2"
Defensive patterns

Strategy: validation

Validate before calling

# Pre-scan the DDL for types this convertor cannot map
SUPPORTED = {"varchar","int","int unsigned","int unsigned zerofill","bigint","bigint unsigned",
    "tinyint","smallint","tinyint unsigned","datetime","timestamp null","date","json",
    "double","timestamp","bit","text","longtext","blob","mediumblob","longblob","decimal"}
for ddl in ddls:
    for col in ddl["columns"]:
        if col["name"].lower() == "deleted":
            continue
        if col["type"].lower() not in SUPPORTED:
            raise SystemExit(f"Unsupported type {col['type']} in {ddl['table_name']}.{col['name']} — extend translate_type first")

Type guard

def is_type_supported(convertor, type_name: str, size) -> bool:
    return convertor.translate_type(type_name.lower(), size) is not None

Prevention

When it happens

Trigger: Running the convertor (e.g. PostgreSQLConvertor) on a MySQL DDL that contains a column type absent from that convertor's translate_type chain. The error message embeds col['type'], the column name, and ddl['table_name'] so the exact column is identifiable.

Common situations: Source SQL includes MySQL-specific or rarely-used types (enum, set, year, mediumint, tinytext, mediumtext, geometry, point, char(n), float, real, numeric without size handling); a new schema migration adds an exotic type; using a target dialect whose convertor has a narrower type map than another convertor.

Related errors


AI-assisted analysis of YunaiV/ruoyi-vue-pro@0418084e22 (2026-08-14). Data as JSON: /api/errors/c953ff34bdd23191. Report an issue: GitHub.