# `data.record_version_invalid`

An entity keeps more than one `RecordVersion`, or one that can be `none`.

Area 5, [Entities, stores and migrations](/docs/data.md); not declinable; the next step is usually the agent's.

## Why Jadpo refuses it

A field typed `RecordVersion` is the record's version. Jadpo sets it to 1
when the record is created and moves it on by one with every change, so
a change made from an old copy can say which version it saw and be
refused when that isn't the stored one. Every record has a version, so it
is never optional, and one version says everything two would.

## What it looks like

main.jadpo:

```jadpo
type TodoTitle = Text {
    max_length: 200
}

entity Todo {
    id: Uuid
    title: TodoTitle
    version: RecordVersion
    revision: RecordVersion
}
```

```text
error: `Todo` keeps a second version, `revision`
 --> main.jadpo:9:5
  |
8 |     version: RecordVersion
  |     ------- its version
9 |     revision: RecordVersion
  |     ^^^^^^^^ a second `RecordVersion`
  reason: Jadpo keeps one version a record, which every change moves on; a second would always hold the same number as `version`.
  next: Remove `revision`, and read `Todo.version` instead (agent)
  rule: data.record_version_invalid
  help: https://jadpo.dev/docs/errors/data.record_version_invalid

check failed: 1 error, 1 file
```

`(agent)` at the end of the `next:` line means your coding agent can make
the fix itself.

A version that can be `none` is refused the same way:

```jadpo
type TodoTitle = Text {
    max_length: 200
}

entity Todo {
    id: Uuid
    title: TodoTitle
    version: RecordVersion?
}
```

```text
error: `Todo.version` can be `none`
 --> main.jadpo:8:5
  |
8 |     version: RecordVersion?
  |     ^^^^^^^ can be `none`
  reason: A record's version is 1 when it is created and one more after every change, so every record has one; `RecordVersion` is never optional.
  next: Write `version: RecordVersion` (agent)
  rule: data.record_version_invalid
  help: https://jadpo.dev/docs/errors/data.record_version_invalid

check failed: 1 error, 1 file
```

## How to fix it

**If the entity keeps a version**, keep one required `RecordVersion`,
and read it wherever the other was read:

```jadpo
entity Todo {
    id: Uuid
    title: TodoTitle
    version: RecordVersion
}
```


Each new todo starts at version 1, and every change Jadpo makes to it
moves `version` on.

## Related

- [A change made from an old copy](/docs/when-a-write-is-refused.md#a-change-made-from-an-old-copy)
- [Fields and their settings](/docs/fields-and-their-settings.md)
- [`data.expected_version_unversioned`](/docs/errors/data.expected_version_unversioned.md)
