# event-schema-unregistered

An event has a type **without a schema**, while the database **requires schemas**.

- **Routes:** `write-events`, `restore-backup`, and `import-events`
- **Description:** `/events/<index>: event type has no registered schema, and schemas are required` when writing events, with the place of the event in its list, counting from 0, and `event type has no registered schema, and schemas are required` when restoring a backup or importing events
- **Details:** When writing events, **`event`**, the place of the event in its list, counting from 0, and **`value`**, its event type. When restoring a backup or importing events, **`eventId`**, the ID of the event, and **`value`**, its event type.

## Why It Happens

The server was started with **`--require-event-schemas`**, which **[enforces known event types](/docs/eventsourcingdb/cli#requiring-event-schemas)**: an event can only be written if its type has a schema. An event of a type that nobody has registered a schema for yet, such as a new one, is refused, and with it the whole write. Without the flag, which is off by default, events of any type are written.

Restoring a backup follows the same rule: every event of the backup needs a schema for its type that the backup registers before it. So does importing events: every event needs a schema for its type that was registered before the import.

## How to Fix It

Register a schema for the event type, and then send the write again, which then succeeds as far as its events match the schema. A restore needs an empty database, so no schema can be registered before it, see **[`store-not-empty`](/docs/eventsourcingdb/errors/store-not-empty)**: restore such a backup on a server started without `--require-event-schemas`. An import takes a database that holds schemas, so register the missing schema, and import the events again.

## Example

For a write of an event of the type `io.eventsourcingdb.library.book-borrowed`, which has no schema, while the database requires schemas, EventSourcingDB answers with this error, as a line of the stream, and then ends the stream with its `end` item:

```json
{
  "type": "error",
  "data": {
    "code": "https://docs.eventsourcingdb.io/errors/event-schema-unregistered",
    "description": "/events/0: event type has no registered schema, and schemas are required",
    "details": {
      "event": 0,
      "value": "io.eventsourcingdb.library.book-borrowed"
    }
  }
}
```
