# Templates

> Use templates in Schemity to define a reusable field structure so every new entity starts with the same fields - an id, timestamps, tenant columns, and more.

Source: https://schemity.com/doc/templates/

A **template** is a reusable set of fields you define once so that every new entity starts with the same structure. If every table in your schema should have an `id`, a `created_at`, and an `updated_at`, you do not want to add them by hand each time - you set up a template, mark it active, and Schemity fills those fields in for you on every new entity.

## How do I open the Template manager?

Click **Open Template manager** in the control bar to open the **ERD template** drawer. It has two views: the list of templates, and the detail view of a single template's fields.

## How do I create a template?

1. In the Template manager, click **Add template** (or the `+` button).
2. In the **Create new template** dialog, give it a **Name** (required) and an optional **Color**.
3. Open the new template's detail view and add the **fields** it should contain.

Template fields are ordinary fields: each has a name, data type (with length, precision, and scale), nullable and unique flags, a default value, and a key type such as primary key. See [Entities & Fields](https://schemity.com/doc/tables-and-fields/) for what each property means.

You can create as many templates as you like - for example a `Base` template with `id` and timestamps, and a `Tenant` template that also adds a `tenant_id`.

## How do I set the active template?

Only one template is active at a time. In the template list, click the **checkmark** next to a template to make it active; click it again to deselect. The active template is marked with the checkmark and a highlighted row.

If no template is active, new entities start empty.

## How do new entities inherit the template's fields?

While a template is active, **every new entity you create automatically receives a copy of the template's fields** - names, types, defaults, nullable and unique flags, and the primary key. You can then add entity-specific fields on top, or remove any you do not need.

A few details worth knowing:

- It applies to **new entities only**. Editing or deleting a template never changes entities you already created.
- **Foreign keys are not carried over** from a template (the fields are meant to be a generic starting structure).
- The template's **color is not applied** to the entity; the entity keeps its own color.

## How do I edit or delete a template?

From the template list you can **Edit** a template's name and color, manage its fields in the detail view (add, edit, delete), or **Delete** the template entirely. Deleting a template removes only the template - entities that were created from it keep their fields.

## Where are templates saved?

Templates are saved per connection, inside the same [JSON file](https://schemity.com/doc/json-storage-format/) as the rest of that diagram (under a `templates` section). They travel with the diagram, so anyone who opens it gets the same templates. Note that templates belong to the main diagram; entities shown inside a [context view](https://schemity.com/doc/context-views/) are read-only there.

## Next

Connect your entities with [Relationships](https://schemity.com/doc/relationships/).
