# Model reference

https://docs.serverpod.dev/next/concepts/lookups/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](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md).

| **Keyword**                                                                                                                                         | Note                                                                                                                                                                                                                                                                  | [class](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#class) | [exception](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#exception) | [enum](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#enum) |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------: |
| [**values**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#enum)                                                         | A special key for enums with a list of all enum values.                                                                                                                                                                                                               |                                                                                         |                                                                                                 |                                           ✅                                           |
| [**serialized**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#enum)                                                     | Sets the mode enums are serialized in.                                                                                                                                                                                                                                |                                                                                         |                                                                                                 |                                           ✅                                           |
| [**properties**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#enhanced-enums-with-properties)                           | Defines custom properties for enhanced enums.                                                                                                                                                                                                                         |                                                                                         |                                                                                                 |                                           ✅                                           |
| [**immutable**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#immutable-classes)                                         | Boolean flag to generate an immutable class with final fields, equals operator, and hashCode.                                                                                                                                                                         |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**serverOnly**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#limiting-visibility-of-a-generated-class)                 | Boolean flag if code generator only should create the code for the server.                                                                                                                                                                                            |                                            ✅                                            |                                                ✅                                                |                                           ✅                                           |
| [**table**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/tables.md)                                                      | A name for the database table, enables generation of database code.                                                                                                                                                                                                   |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**database**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/tables.md#choosing-where-a-table-lives)                      | Where a table lives: `server` (default), `client`, or `all`.                                                                                                                                                                                                          |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**managedMigration**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/migrations.md#opt-out-of-migrations)                 | A boolean flag to opt out of the database migration system.                                                                                                                                                                                                           |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**serializationDataType**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/tables.md#storing-serializable-fields-as-jsonb) | Stores serializable fields as `json` or `jsonb`. Valid on classes and on individual fields.                                                                                                                                                                           |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**fields**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#class)                                                        | All fields in the generated class should be listed here.                                                                                                                                                                                                              |                                            ✅                                            |                                                ✅                                                |                                                                                       |
| [**type (fields)**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#class)                                                 | Denotes the data type for a field.                                                                                                                                                                                                                                    |                                            ✅                                            |                                                ✅                                                |                                                                                       |
| [**required**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#required-fields)                                            | Makes the field required. This keyword can only be used for **nullable** fields.                                                                                                                                                                                      |                                            ✅                                            |                                                ✅                                                |                                                                                       |
| [**tail**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models/inheritance-and-polymorphism.md#ordering-inherited-fields)         | Places the field after all normal fields of an inheritance hierarchy. Child tail fields come before parent tail fields. Not allowed on the `id` field.                                                                                                                |                                            ✅                                            |                                                ✅                                                |                                                                                       |
| [**scope**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#limiting-visibility-of-a-generated-class)                      | Denotes the scope for a field.                                                                                                                                                                                                                                        |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**jsonKey**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#json-key-aliasing)                                           | Sets a custom key name for JSON serialization and deserialization.                                                                                                                                                                                                    |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**column**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/tables.md#column-name-override)                                | Overrides the database column name for a field.                                                                                                                                                                                                                       |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**persist**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/tables.md)                                                    | A boolean flag if the data should be stored in the database or not can be negated with `!persist`                                                                                                                                                                     |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**relation**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations.md)                                                | Sets a relation between model files, requires a table name to be set.                                                                                                                                                                                                 |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**name**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations/one-to-one.md#bidirectional-relations)                 | Give a name to a relation to pair them.                                                                                                                                                                                                                               |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**parent**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations/one-to-one.md#with-an-id-field)                      | Sets the parent table on a relation.                                                                                                                                                                                                                                  |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**field**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations/one-to-one.md#custom-foreign-key-field)               | A manual specified foreign key field.                                                                                                                                                                                                                                 |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**onUpdate**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations/referential-actions.md)                            | Set the referential actions when updating data in the database.                                                                                                                                                                                                       |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**onDelete**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations/referential-actions.md)                            | Set the referential actions when deleting data in the database.                                                                                                                                                                                                       |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**optional**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations/one-to-one.md#optional-relation)                   | A boolean flag to make a relation optional.                                                                                                                                                                                                                           |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**deferrable**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations/deferrable-constraints.md)                       | Make the foreign key constraint deferrable, checked after each statement unless a transaction defers it.                                                                                                                                                              |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**deferred**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/relations/deferrable-constraints.md)                         | Make the foreign key constraint deferrable and checked at commit. Mutually exclusive with **deferrable**.                                                                                                                                                             |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**indexes**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/indexing.md)                                                  | Create indexes on your fields / columns.                                                                                                                                                                                                                              |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**fields (index)**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/indexing.md)                                           | List the fields to create the indexes on.                                                                                                                                                                                                                             |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**type (index)**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/indexing.md)                                             | The type of index to create.                                                                                                                                                                                                                                          |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**parameters (index)**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/indexing.md#vector-indexes)                        | Parameters for specialized index types like HNSW and IVFFLAT vector indexes.                                                                                                                                                                                          |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**distanceFunction (index)**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/indexing.md#vector-indexes)                  | Distance function for vector indexes. Allowed values depend on the field's vector type and index type, see [vector indexes](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/indexing.md#vector-indexes).                                      |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**operatorClass (index)**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/indexing.md#operator-classes)                   | Operator class for GIN indexes.                                                                                                                                                                                                                                       |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**unique**](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/indexing.md#make-fields-unique)                                | Creates a unique index. Also valid directly on a field, optionally scoped with `unique(per=...)`.                                                                                                                                                                     |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**default**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#default-values)                                              | Sets 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](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#handling-unknown-enum-values). |                                            ✅                                            |                                                ✅                                                |                                           ✅                                           |
| [**defaultModel**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#default-values)                                         | Sets the default value for the model side. This keyword cannot be used with **relation**.                                                                                                                                                                             |                                            ✅                                            |                                                ✅                                                |                                                                                       |
| [**defaultPersist**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md#default-values)                                       | Sets the default value for the database side. This keyword cannot be used with **relation** and **!persist**.                                                                                                                                                         |                                            ✅                                            |                                                                                                 |                                                                                       |
| [**extends**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models/inheritance-and-polymorphism.md#extending-a-class)              | Specifies a parent class or exception of the same kind to inherit from.                                                                                                                                                                                               |                                            ✅                                            |                                                ✅                                                |                                                                                       |
| [**sealed**](https://docs.serverpod.dev/next/concepts/data-and-the-database/models/inheritance-and-polymorphism.md#sealed-classes)                  | Boolean flag to create a sealed class or exception hierarchy, enabling exhaustive type checking.                                                                                                                                                                      |                                            ✅                                            |                                                ✅                                                |                                                                                       |

## Related

- [Working with models](https://docs.serverpod.dev/next/concepts/data-and-the-database/models.md): how each keyword works, with examples.
- [Dynamic fields](https://docs.serverpod.dev/next/concepts/data-and-the-database/models/dynamic-fields.md): store and transfer values whose type varies at runtime.
- [Serializable exceptions](https://docs.serverpod.dev/next/concepts/endpoints-and-apis/error-handling-and-exceptions.md#serializable-exceptions): define, inherit, throw, and catch application errors.
- [Database tables](https://docs.serverpod.dev/next/concepts/data-and-the-database/database/tables.md): the database-specific keywords (`table`, `relation`, `persist`, and indexing).
