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.
| Keyword | Note | class | exception | enum |
|---|---|---|---|---|
| values | A special key for enums with a list of all enum values. | ✅ | ||
| serialized | Sets the mode enums are serialized in | ✅ | ||
| properties | Defines custom properties for enhanced enums. | ✅ | ||
| immutable | Boolean flag to generate an immutable class with final fields, equals operator, and hashCode. | ✅ | ✅ | |
| serverOnly | Boolean flag if code generator only should create the code for the server. | ✅ | ✅ | ✅ |
| table | A name for the database table, enables generation of database code. | ✅ | ||
| managedMigration | A boolean flag to opt out of the database migration system. | ✅ | ||
| fields | All fields in the generated class should be listed here. | ✅ | ✅ | |
| type (fields) | Denotes the data type for a field. | ✅ | ✅ | |
| required | Makes the field as required. This keyword can only be used for nullable fields. | ✅ | ✅ | |
| scope | Denotes the scope for a field. | ✅ | ||
| jsonKey | Sets a custom key name for JSON serialization and deserialization. | ✅ | ||
| persist | A boolean flag if the data should be stored in the database or not can be negated with !persist | ✅ | ||
| relation | Sets a relation between model files, requires a table name to be set. | ✅ | ||
| name | Give a name to a relation to pair them. | ✅ | ||
| parent | Sets the parent table on a relation. | ✅ | ||
| field | A manual specified foreign key field. | ✅ | ||
| onUpdate | Set the referential actions when updating data in the database. | ✅ | ||
| onDelete | Set the referential actions when deleting data in the database. | ✅ | ||
| optional | A boolean flag to make a relation optional. | ✅ | ||
| indexes | Create 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. | ✅ | ||
| unique | Creates a unique index. | ✅ | ||
| default | Sets the default value for both the model and the database. This keyword cannot be used with relation. | ✅ | ||
| defaultModel | Sets the default value for the model side. This keyword cannot be used with relation. | ✅ | ||
| defaultPersist | Sets the default value for the database side. This keyword cannot be used with relation and !persist. | ✅ | ||
| extends | Specifies a parent class to inherit from. | ✅ | ✅ | |
| sealed | Boolean flag to create a sealed class hierarchy, enabling exhaustive type checking. | ✅ |
Related
- Working with models: how each keyword works, with examples.
- Database tables: the database-specific keywords (
table,relation,persist, and indexing).