{"record":{"id":"c254f9355986c644","repo":"OpenAPITools/openapi-generator","slug":"the-blob-text-geometry-and-json-data-types-cann-c254f9","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/PostgresqlSchemaCodegen.java","lineNumber":1176,"sourceCode":"                    defaultMap.put(\"isNumeric\", false);\n                    defaultMap.put(\"isKeyword\", true);\n\n                } else {\n                    defaultMap.put(\"defaultValue\", defaultValue);\n                    defaultMap.put(\"isString\", true);\n                    defaultMap.put(\"isNumeric\", false);\n                    defaultMap.put(\"isKeyword\", false);\n\n                }\n                return defaultMap;\n            case \"BYTEA\":\n            case \"TEXT\":\n            case \"GEOMETRY\":\n            case \"JSON\":\n            case \"JSONB\":\n                // The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default\n                // value.\n                throw new RuntimeException(\n                        \"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\n                return defaultMap;\n        }\n    }\n\n    /**\n     * Finds best fitted PostgreSQL data type for integer variable based on minimum\n     * 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","sourceCodeStart":1158,"sourceCodeEnd":1194,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostgresqlSchemaCodegen.java#L1158-L1194","documentation":"PostgreSQL does not allow DEFAULT values on BYTEA, TEXT, GEOMETRY, JSON and JSONB columns (expression defaults like DEFAULT '{}'::jsonb are a separate SQL feature the generator does not emit). When PostgresqlSchemaCodegen's default-processing switch is handed a `default` for any of those types, it throws a RuntimeException (PostgresqlSchemaCodegen.java:1176) rather than generate invalid DDL; all other types fall through and record the default.","triggerScenarios":"Generating SQL with the postgresql generator from a spec where a property mapped to BYTEA (format: binary), TEXT (long unbounded string), JSON/JSONB (type: object, or string with x-postgres-type json/jsonb), or GEOMETRY has a non-null `default`.","commonSituations":"Designing the API spec and DB schema from one source; carrying sample/default payload values from API docs into schema generation; migrating from a generator that ignored unsupported defaults to one that fails fast.","solutions":["Remove the `default` from the offending property in the spec.","Add expression defaults (e.g. DEFAULT '{}'::jsonb) via a hand-maintained migration on top of the generated schema.","Or change the column type to one permitting defaults (bounded string → VARCHAR with default)."],"exampleFix":"# before (api.yaml)\ncomponents:\n  schemas:\n    Profile:\n      properties:\n        prefs:\n          type: object\n          default: {\"newsletter\": true}\n# after\ncomponents:\n  schemas:\n    Profile:\n      properties:\n        prefs:\n          type: object","handlingStrategy":"validation","validationCode":"// postgresql: reject defaults on properties mapping to BYTEA/TEXT/JSON/JSONB/GEOMETRY\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 bytea = \"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 && (bytea || json || text)) {\n      throw new IllegalArgumentException(\"PostgreSQL DEFAULT not allowed on BYTEA/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(\"PostgreSQL schema generation failed: \" + e.getMessage(), e);\n}","preventionTips":["Use `example:` for illustrative values; only use `default:` on types PostgreSQL allows defaults on.","Set maxLength on long strings so they map to VARCHAR rather than TEXT.","Keep JSONB expression defaults in manual migrations layered over generated DDL."],"tags":["postgresql","database-schema","default-value","bytea","jsonb","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"}