{"record":{"id":"ed6723aaca2a6ed0","repo":"OpenAPITools/openapi-generator","slug":"the-blob-text-geometry-and-json-data-types-cann","errorCode":null,"errorMessage":"The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default value","messagePattern":"The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default value","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MysqlSchemaCodegen.java","lineNumber":915,"sourceCode":"                } else {\n                    defaultMap.put(\"defaultValue\", defaultValue);\n                    defaultMap.put(\"isString\", true);\n                    defaultMap.put(\"isNumeric\", false);\n                    defaultMap.put(\"isKeyword\", false);\n                }\n                return defaultMap;\n            case \"TINYBLOB\":\n            case \"BLOB\":\n            case \"MEDIUMBLOB\":\n            case \"LONGBLOB\":\n            case \"TINYTEXT\":\n            case \"TEXT\":\n            case \"MEDIUMTEXT\":\n            case \"LONGTEXT\":\n            case \"GEOMETRY\":\n            case \"JSON\":\n                // The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default value.\n                throw new RuntimeException(\"The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default value\");\n            default:\n                defaultMap.put(\"defaultValue\", defaultValue);\n                defaultMap.put(\"isString\", true);\n                defaultMap.put(\"isNumeric\", false);\n                defaultMap.put(\"isKeyword\", false);\n                return defaultMap;\n        }\n    }\n\n    /**\n     * Finds best fitted MySQL data type for integer variable based on minimum and maximum properties\n     *\n     * @param minimum  (optional) codegen property\n     * @param maximum  (optional) codegen property\n     * @param unsigned (optional) whether variable is unsigned or not\n     * @return MySQL integer data type\n     */\n    public String getMysqlMatchedIntegerDataType(Long minimum, Long maximum, Boolean unsigned) {","sourceCodeStart":897,"sourceCodeEnd":933,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MysqlSchemaCodegen.java#L897-L933","documentation":"MySQL itself forbids literal DEFAULT values on BLOB, TEXT, GEOMETRY and JSON columns (MySQL 8 only allows expression defaults on JSON, which the generator does not emit). When MysqlSchemaCodegen maps a `default` onto one of those column types — TINYBLOB/BLOB/MEDIUMBLOB/LONGBLOB, the TEXT family, GEOMETRY, JSON — the default-processing switch throws a RuntimeException (MysqlSchemaCodegen.java:915) instead of emitting invalid DDL.","triggerScenarios":"Generating SQL schema with the mysql generator from a spec where a property mapped to one of those types has a `default`: object properties (JSON), long unbounded strings (TEXT), or format: binary properties (BLOB).","commonSituations":"Reusing an API spec as the source of truth for DDL generation; specs where object/free-text fields carry sample defaults; teams moving from generators that silently drop such defaults to ones that fail fast.","solutions":["Delete the `default` from the offending property in the spec (the message is thrown per offending column).","For JSON columns needing a default, add an explicit expression default (DEFAULT (JSON_OBJECT())) in a hand-written migration — the generator cannot emit it.","Or tighten the property type so it maps to a type that allows defaults (e.g. bounded string → VARCHAR)."],"exampleFix":"# before (api.yaml)\ncomponents:\n  schemas:\n    Account:\n      properties:\n        bio:\n          type: string\n          maxLength: 100000\n          default: \"n/a\"\n# after\ncomponents:\n  schemas:\n    Account:\n      properties:\n        bio:\n          type: string\n          maxLength: 100000","handlingStrategy":"validation","validationCode":"// mysql: reject defaults on properties that map to BLOB/TEXT/GEOMETRY/JSON columns\nfor (var e : openAPI.getComponents().getSchemas().entrySet()) {\n  Map<String, Schema> props = e.getValue().getProperties();\n  if (props == null) continue;\n  for (var p : props.entrySet()) {\n    Schema s = p.getValue();\n    boolean binary = \"string\".equals(s.getType()) && \"binary\".equals(s.getFormat());\n    boolean json = \"object\".equals(s.getType());\n    boolean text = \"string\".equals(s.getType()) && s.getMaxLength() == null;\n    if (s.getDefault() != null && (binary || json || text)) {\n      throw new IllegalArgumentException(\"MySQL DEFAULT not allowed on BLOB/TEXT/JSON property '\"\n          + p.getKey() + \"' in '\" + e.getKey() + \"'\");\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n    new DefaultGenerator().opts(clientOptInput).generate();\n} catch (RuntimeException e) {\n    throw new BuildException(\"MySQL schema generation failed: \" + e.getMessage(), e);\n}","preventionTips":["Use `example:` for documentation values; reserve `default:` for types MySQL permits defaults on.","Give long string fields a maxLength so they map to VARCHAR (defaults allowed) instead of TEXT.","Maintain JSON/expression defaults in hand-written migrations, not in the spec."],"tags":["mysql","database-schema","default-value","blob","text","json","openapi-spec","openapi-generator","spec-validation"],"backgroundTag":"default-value-on-blob-column","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}