Skip to main content
Version: Next

Model reference

Every keyword available in a Serverpod model file, and whether it applies to a class, exception, or enum. For how each one works, see Working with models.

KeywordNoteclassexceptionenum
valuesA special key for enums with a list of all enum values.
serializedSets the mode enums are serialized in.
propertiesDefines custom properties for enhanced enums.
immutableBoolean flag to generate an immutable class with final fields, equals operator, and hashCode.
serverOnlyBoolean flag if code generator only should create the code for the server.
tableA name for the database table, enables generation of database code.
databaseWhere a table lives: server (default), client, or all.
managedMigrationA boolean flag to opt out of the database migration system.
serializationDataTypeStores serializable fields as json or jsonb. Valid on classes and on individual fields.
fieldsAll fields in the generated class should be listed here.
type (fields)Denotes the data type for a field.
requiredMakes the field required. This keyword can only be used for nullable fields.
tailPlaces the field after all normal fields of an inheritance hierarchy. Child tail fields come before parent tail fields. Not allowed on the id field.
scopeDenotes the scope for a field.
jsonKeySets a custom key name for JSON serialization and deserialization.
columnOverrides the database column name for a field.
persistA boolean flag if the data should be stored in the database or not can be negated with !persist
relationSets a relation between model files, requires a table name to be set.
nameGive a name to a relation to pair them.
parentSets the parent table on a relation.
fieldA manual specified foreign key field.
onUpdateSet the referential actions when updating data in the database.
onDeleteSet the referential actions when deleting data in the database.
optionalA boolean flag to make a relation optional.
indexesCreate indexes on your fields / columns.
fields (index)List the fields to create the indexes on.
type (index)The type of index to create.
parameters (index)Parameters for specialized index types like HNSW and IVFFLAT vector indexes.
distanceFunction (index)Distance function for vector indexes. Allowed values depend on the field's vector type and index type, see vector indexes.
operatorClass (index)Operator class for GIN indexes.
uniqueCreates a unique index. Also valid directly on a field, optionally scoped with unique(per=...).
defaultSets the default value for both the model and the database. This keyword cannot be used with relation. On an enum, sets the fallback for unknown values.
defaultModelSets the default value for the model side. This keyword cannot be used with relation.
defaultPersistSets the default value for the database side. This keyword cannot be used with relation and !persist.
extendsSpecifies a parent class or exception of the same kind to inherit from.
sealedBoolean flag to create a sealed class or exception hierarchy, enabling exhaustive type checking.