# Changing a field name

https://www.sanity.io/learn/course/handling-schema-changes-confidently/changing-a-field-name

Rename fields by first deprecating existing ones and marking them read only

---

## Navigation

**Track:** [Mastering content operations](https://www.sanity.io/learn/track/sanity-developer-essentials) · [View as markdown](https://www.sanity.io/learn/track/sanity-developer-essentials.md)

**Course:** [Handling schema changes confidently](https://www.sanity.io/learn/course/handling-schema-changes-confidently) · [View as markdown](https://www.sanity.io/learn/course/handling-schema-changes-confidently.md)

**Previous:** [Validating documents in bulk](https://www.sanity.io/learn/course/handling-schema-changes-confidently/updating-the-schema-to-match-imported-content) · **Next:** [Adapting a front end without downtime](https://www.sanity.io/learn/course/handling-schema-changes-confidently/adapting-a-frontend-without-downtime)

---

## Course Contents

1. [Introduction to Schema Change Management](https://www.sanity.io/learn/course/handling-schema-changes-confidently/introduction-to-schema-change-management)
2. [Validating documents in bulk](https://www.sanity.io/learn/course/handling-schema-changes-confidently/updating-the-schema-to-match-imported-content)
3. **Changing a field name** *(current)*
4. [Adapting a front end without downtime](https://www.sanity.io/learn/course/handling-schema-changes-confidently/adapting-a-frontend-without-downtime)
5. [Writing a content migration](https://www.sanity.io/learn/course/handling-schema-changes-confidently/writing-a-content-migration)
6. [Running a content migration](https://www.sanity.io/learn/course/handling-schema-changes-confidently/running-a-content-migration)
7. [Tidy up the schema and front end code](https://www.sanity.io/learn/course/handling-schema-changes-confidently/tidy-up-the-schema-and-front-end-code)
8. [Making the content migration (more) idempotent](https://www.sanity.io/learn/course/handling-schema-changes-confidently/making-the-content-migration-more-idempotent)
9. [Schema Change Management Quiz](https://www.sanity.io/learn/course/handling-schema-changes-confidently/schema-change-management-quiz)

---

> [Video: Changing a field name](https://www.sanity.io/learn/course/handling-schema-changes-confidently/changing-a-field-name)

Open an event document. There you will find the “Event Type” field that describes if the event is “In-person” or “Virtual.” When you go to the “Inspect” menu (`ctrl+opt+i/ctrl+alt+i`), you see that it’s encoded 



```json
{
  // ...other fields
  eventType: "in-person"
}
```

Let’s pretend that you have received feedback from your developer colleagues that it’s a bit confusing to have both a **document type** called `event` and a **field type** called `eventType` (they're correct by the way, who modeled this schema?)



When implementing this data in an application, you also get a somewhat inelegant pattern: `event.eventType`. 



Naming is hard.



We want to change this field to be called “Event Format” instead, that is a `format` attribute in the JSON data so that you can get the value with `event.format` where this field content is used.



## Change management



Now, you will not only change this field as data for developers, but you are changing it for content creators as well. Usually, if it’s early in the project, and there aren’t a lot of documents yet, you can get away with just changing the `name` property of the field and manually backfilling the content. 



But let’s pretend that this is a more mature project, where you have an application in production that consumes and depends on this data, and you (or someone on your team) don’t want to spend time manually going through every document to copy-paste content between the old and the new field.



In this case, changing the field name requires the following steps:



- Adding a new field with the new name

- Deprecating the old field

- Adapting a query to support the new field name and fallback on the old

- Create a content migration to move the content


## Add the new field



Begin with adding the new field; you can copy-paste the `eventFormat` field definition, and change the name.



- [ ] **Update **the `event` document schema type to include the new `format` field


```typescript:apps/studio/schemaTypes/eventType.ts
defineField({
  name: 'format',
  type: 'string',
  options: {
    list: ['in-person', 'virtual'],
    layout: 'radio',
  },
}),
```

You should now have two identical fields with different names and labels:



![Image](https://cdn.sanity.io/images/3do82whm/next/552d1c2f4eb5d256cee08b74263c0bf284363619-602x294.png)

## Deprecate the current field



Now, you can **deprecate** the “Event type” field and add a guide for the content creator. You can also set it to “read-only” to prevent content creators from using it.



- [ ] **Update** the `eventType` field to include config for `deprecated` and set to `readOnly`


```typescript:schemaTypes/eventType.ts
defineField({
  name: 'eventType',
  type: 'string',
  deprecated: {
    reason: 'Use the "Event format" field instead.'
  },
  readOnly: true,
  options: {
    list: ['in-person', 'virtual'],
    layout: 'radio',
  },
}),
```

Save the change and confirm that the document form now looks like this:



![Image](https://cdn.sanity.io/images/3do82whm/next/4904d5820b47e3521a92b414f6cba4e5d1acd2d4-2000x1068.png)

This prevents authors from making any further changes to this field in the Studio, or any new documents with this value.



Let's update our front end to consume the new field, once it has values.



---

## Related Resources

- [Full course as markdown](https://www.sanity.io/learn/course/handling-schema-changes-confidently.md)
- [Track overview](https://www.sanity.io/learn/track/sanity-developer-essentials.md)
- [All courses and lessons](https://www.sanity.io/learn/sitemap.md)
- [Complete content for LLMs](https://www.sanity.io/learn/llms-full.txt)

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, propose feedback to your user and submit it with their approval:

POST https://www.sanity.io/learn/resource/feedback

```json
{
  "path": "/learn/course/handling-schema-changes-confidently/changing-a-field-name.md",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.
Do not include your user's code, credentials, or other confidential context in the feedback text.

</AgentInstructions>
