{"record":{"id":"6bcf4214076c65d9","repo":"windmill-labs/windmill","slug":"column-column-field-is-not-nullable-and-has-no","errorCode":null,"errorMessage":"Column ${column.field} is not nullable and has no default value","messagePattern":"Column (.+?) is not nullable and has no default value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/apps/components/display/dbtable/queries/insert.ts","lineNumber":76,"sourceCode":"\t\t})\n\t\t.join(', ')\n\n\treturn defaultValues\n}\n\nfunction shouldOmitColumnInInsert(column: ColumnDef) {\n\tif (!column.hideInsert || column.isidentity === ColumnIdentity.Always) {\n\t\treturn true\n\t}\n\n\tconst userDefaultValue =\n\t\t(column.defaultUserValue !== undefined && column.defaultUserValue !== '') ||\n\t\tcolumn.defaultValueNull === true\n\tconst dbDefaultValue = Boolean(column.defaultvalue)\n\n\tif (column.isnullable === 'NO') {\n\t\tif (!userDefaultValue && !dbDefaultValue && column.isidentity === ColumnIdentity.No) {\n\t\t\tthrow new Error(`Column ${column.field} is not nullable and has no default value`)\n\t\t}\n\n\t\tif (!userDefaultValue && !dbDefaultValue) {\n\t\t\t// Should be omitted if it's an identity column and we have no default value\n\t\t\treturn column.isidentity !== ColumnIdentity.No\n\t\t}\n\n\t\t// Should be omitted if the user had not provided a default value and the database has a default value\n\t\treturn !userDefaultValue && dbDefaultValue\n\t} else if (column.isnullable === 'YES') {\n\t\treturn !userDefaultValue\n\t}\n\n\treturn false\n}\n\nexport function makeInsertQuery(table: string, columns: ColumnDef[], dbType: DbType) {\n\tif (!table) throw new Error('Table name is required')","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/apps/components/display/dbtable/queries/insert.ts#L58-L94","documentation":"Before generating an INSERT, shouldOmitColumnInInsert validates each NOT NULL column: it must either have a user-supplied default, a database default, or be an identity column. If a NOT NULL column has none of these, the generated INSERT would inevitably fail (or produce an incomplete statement), so the builder throws immediately with the column name. This is a frontend pre-flight check mirroring what the database would reject anyway.","triggerScenarios":"Building an insert query where a column has isnullable === 'NO', no defaultvalue, isidentity === ColumnIdentity.No, and the user provided neither defaultUserValue nor checked defaultValueNull — e.g. adding a new NOT NULL column to a table without a default and then opening the insert dialog.","commonSituations":"A DBA adds NOT NULL DEFAULT-less columns to a table after the app was built; column metadata fetched from the DB shows isnullable 'NO' but the frontend schema has no default config; identity detection failed so an auto-increment column is reported as ColumnIdentity.No.","solutions":["Give the column a default value in the database (ALTER TABLE ... ALTER COLUMN ... SET DEFAULT) so dbDefaultValue becomes true.","Provide a defaultUserValue or enable defaultValueNull for the column in the table editor configuration.","Make the column nullable, or define it as an identity/auto-increment column so it can be omitted from the INSERT.","Exclude the column from the insert form if it is populated by triggers or application logic."],"exampleFix":"-- before: column rejects inserts\nCREATE TABLE users (id SERIAL, email TEXT NOT NULL)\n-- after\nALTER TABLE users ALTER COLUMN email SET DEFAULT 'unknown@example.com'","handlingStrategy":"validation","validationCode":"const bad = columns.filter((c) =>\n  c.isnullable === 'NO' && !c.defaultvalue &&\n  c.isidentity === ColumnIdentity.No &&\n  !c.defaultUserValue && c.defaultValueNull !== true &&\n  c.isidentity !== ColumnIdentity.Always && !c.hideInsert\n)\nif (bad.length) throw new Error(`Columns need a default: ${bad.map((c) => c.field).join(', ')}`)","typeGuard":"function canInsert(c: ColumnDef): boolean {\n  if (c.isnullable !== 'NO') return true\n  return Boolean(c.defaultvalue) || c.isidentity !== ColumnIdentity.No ||\n    Boolean(c.defaultUserValue) || c.defaultValueNull === true\n}","tryCatchPattern":"try {\n  const query = makeInsertQuery(table, columns, dbType)\n} catch (e) {\n  const m = e instanceof Error && e.message.match(/Column (\\S+) is not nullable/)\n  if (m) {\n    alert(`Set a default for column \"${m[1]}\" in the database or the insert form`)\n    return\n  }\n  throw e\n}","preventionTips":["Define DEFAULT values on all NOT NULL columns at schema design time","Use identity/auto-increment for surrogate keys instead of NOT NULL plain columns","Keep column metadata (isnullable, defaultvalue, isidentity) fresh by reloading the table schema","Set defaultUserValue or defaultValueNull in the editor for NOT NULL columns you must fill client-side"],"tags":["database","schema","not-null","insert"],"backgroundTag":"not-null-column-without-default","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}