windmill-labs/windmill · error

Column ${column.field} is not nullable and has no default va

Error message

Column ${column.field} is not nullable and has no default value

What it means

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.

Source

Thrown at frontend/src/lib/components/apps/components/display/dbtable/queries/insert.ts:76

		})
		.join(', ')

	return defaultValues
}

function shouldOmitColumnInInsert(column: ColumnDef) {
	if (!column.hideInsert || column.isidentity === ColumnIdentity.Always) {
		return true
	}

	const userDefaultValue =
		(column.defaultUserValue !== undefined && column.defaultUserValue !== '') ||
		column.defaultValueNull === true
	const dbDefaultValue = Boolean(column.defaultvalue)

	if (column.isnullable === 'NO') {
		if (!userDefaultValue && !dbDefaultValue && column.isidentity === ColumnIdentity.No) {
			throw new Error(`Column ${column.field} is not nullable and has no default value`)
		}

		if (!userDefaultValue && !dbDefaultValue) {
			// Should be omitted if it's an identity column and we have no default value
			return column.isidentity !== ColumnIdentity.No
		}

		// Should be omitted if the user had not provided a default value and the database has a default value
		return !userDefaultValue && dbDefaultValue
	} else if (column.isnullable === 'YES') {
		return !userDefaultValue
	}

	return false
}

export function makeInsertQuery(table: string, columns: ColumnDef[], dbType: DbType) {
	if (!table) throw new Error('Table name is required')

View on GitHub (pinned to e474e8803c)

Solutions

  1. Give the column a default value in the database (ALTER TABLE ... ALTER COLUMN ... SET DEFAULT) so dbDefaultValue becomes true.
  2. Provide a defaultUserValue or enable defaultValueNull for the column in the table editor configuration.
  3. Make the column nullable, or define it as an identity/auto-increment column so it can be omitted from the INSERT.
  4. Exclude the column from the insert form if it is populated by triggers or application logic.

Example fix

-- before: column rejects inserts
CREATE TABLE users (id SERIAL, email TEXT NOT NULL)
-- after
ALTER TABLE users ALTER COLUMN email SET DEFAULT 'unknown@example.com'
Defensive patterns

Strategy: validation

Validate before calling

const bad = columns.filter((c) =>
  c.isnullable === 'NO' && !c.defaultvalue &&
  c.isidentity === ColumnIdentity.No &&
  !c.defaultUserValue && c.defaultValueNull !== true &&
  c.isidentity !== ColumnIdentity.Always && !c.hideInsert
)
if (bad.length) throw new Error(`Columns need a default: ${bad.map((c) => c.field).join(', ')}`)

Type guard

function canInsert(c: ColumnDef): boolean {
  if (c.isnullable !== 'NO') return true
  return Boolean(c.defaultvalue) || c.isidentity !== ColumnIdentity.No ||
    Boolean(c.defaultUserValue) || c.defaultValueNull === true
}

Try / catch

try {
  const query = makeInsertQuery(table, columns, dbType)
} catch (e) {
  const m = e instanceof Error && e.message.match(/Column (\S+) is not nullable/)
  if (m) {
    alert(`Set a default for column "${m[1]}" in the database or the insert form`)
    return
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/6bcf4214076c65d9. Report an issue: GitHub.