Cast errors
Thrown as CastError (code: "cast"). Each entry is an identifier (error.id), then the message as the error states it, where {expression} stands for the value of that expression in the source ({…} for one too long to show), then what to do about it: the text useFullErrorMessages(messages) and explain(error) add, where {name} stands for the error's parameter of that name. See Errors.
cast.bigintFraction
A bigint column received a value from the database that is not a whole number.
Read a fractional numeric column with t.decimal().
cast.bigintNumberRange
A bigint column read with { mode: "number" } holds a value outside the safe integer range of a JavaScript number (±9007199254740991).
Declare the field as t.bigint() to read it as a bigint.
cast.bigintNumberString
A bigint column read with { mode: "number" } received a string from the driver that is not a whole number.
Check the column holds whole numbers; read it with t.decimal() if it holds fractions.
cast.dateInvalidWrite
An invalid Date cannot be written to a date column.
Pass a valid Date, or a "YYYY-MM-DD" string.
cast.dateRange
A Date outside the years 1 to 9999 cannot be written to a date column read with { as: "date" }.
Pass a Date in the years 1 to 9999, or declare the field as t.date() to work with strings.
cast.dateRead
A date column read with { as: "date" } holds a value that is not a "YYYY-MM-DD" date (for example "infinity", or a date before year 1).
Declare the field as t.date() to read it as a string.
cast.embedFieldMissing
{what}, and the field {slot.field.name} has no default and is not nullable.
Give it a .default(…) (or make it .nullable()) so that rows stored before it existed can be read.
cast.embedGeneratedMissing
{what}, the generated value of {slot.field.name}: it was written without one (not through a changeset or insertAll).
Write the row through a changeset or insertAll(), which fill the generated value.
cast.embedInvalidDate
An embedded field holds an invalid Date.
Store a valid Date: the value was created with new Date() from something that is not a date.
cast.embedListNotArray
A list of {target.name} must be an array.
Pass an array of the embedded values; an empty list is [].
cast.embedNotObject
A stored {schemaMeta.name} is not a JSON object.
Fix the stored JSON: an embedOne column holds a JSON object (or null for a nullable embed).
cast.embedStoredField
The stored "{key}" of the embedded {schemaMeta.name} is not {what}.
Fix the stored JSON, or change the embedded field's type to what the column holds.
cast.embedStoredListNotArray
A stored list of {target.name} is not a JSON array.
Fix the stored JSON: an embedMany column holds a JSON array (or null for a nullable embed).
cast.embedWrite
A {target.name} cannot be written: {row}.
Write the embed through a changeset (castEmbed or putEmbed), which checks each field.
cast.enumStoredValue
An enum column holds a {…} that is not one of the enum's stored values ({stored.map((v) => JSON.stringify(v)).join(", ")}).
Add it to the enum, or fix the stored data.
cast.enumWriteValue
A value that is not a member of the enum ({keys.map((k) => JSON.stringify(k)).join(", ")}) cannot be written to an enum column.
Write one of the enum's members; a changeset's cast rejects other values before they reach the database.
cast.floatNotFinite
MySQL cannot store NaN, Infinity or -Infinity in a float column.
SQLite cannot store NaN, Infinity or -Infinity in a float column without losing it.
Store a finite number, or null.
cast.floatNotNumber
{label} is declared t.float(), but the database returned {article} {got} for it, not a number.{after}
The column or expression is not of a floating-point type (Postgres reads numeric columns as text). Declare the field t.decimal() for a decimal column, or change the column's type.
cast.integerNotNumber
{label} is declared t.integer(), but the database returned {article} {got} for it, not a number.{after}
The column or expression is not of an integer type (Postgres reads bigint, bigserial and numeric columns as text; MySQL's / returns a decimal). Declare the field t.bigint({ mode: "number" }) for a 64-bit integer column, or t.decimal() for a decimal, or change the column's type.
cast.jsonInvalid
A JSON column received text from the database that is not valid JSON.
Fix the stored text, or read the column with t.string().
cast.paramsNotObject
cast() expects params to be a plain object (or null or undefined for none), but got {kind}.
Pass the params as a plain object, such as a parsed request body; null and undefined count as no params.
cast.timestampInvalidDate
An invalid Date cannot be written to a timestamp column.
Pass a valid Date: one made from something that is not a date is invalid.
cast.timestampYearRange
MySQL stores datetimes with a four-digit year: 0000 to 9999.
SQLite stores timestamps as text with a four-digit year: 0000 to 9999.
Pass a date in the years 0 to 9999.
cast.unsafeInteger
A number column received an integer from the database beyond Number.MAX_SAFE_INTEGER.
Read it with t.bigint().

