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.
managedMigrationA boolean flag to opt out of the database migration system.
fieldsAll fields in the generated class should be listed here.
type (fields)Denotes the data type for a field.
requiredMakes the field as required. This keyword can only be used for nullable fields.
scopeDenotes the scope for a field.
jsonKeySets a custom key name for JSON serialization and deserialization.
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.
uniqueCreates a unique index.
defaultSets the default value for both the model and the database. This keyword cannot be used with relation.
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 to inherit from.
sealedBoolean flag to create a sealed class hierarchy, enabling exhaustive type checking.