# Make a field readOnly with Sequelize

Sequelize does not allow by itself to define a field as readOnly. But you can do so by using on of Sequelize's addons named [sequelize-noupdate-attributes](https://www.npmjs.com/package/sequelize-noupdate-attributes).

![the LastName field is readOnly in Sequelize but not the email field](/files/-MJBtFOfvSYiBzA_4ElO)

## Requirements

* An admin backend running on forest-express-sequelize
* [sequelize-noupdate-attributes](https://www.npmjs.com/package/sequelize-noupdate-attributes) npm package

## How it works

### Directory: /models

This directory contains the files where your models are defined with Sequelize. To make fields readOnly you need to require the `sequelize-noupdate-attributes` package and add the `noUpdate` option to the relevant fields.

{% hint style="info" %}
The `noUpdate` option will throw an error if the user tries to update a field that already has a value. However the user will be able to update a field that has a `null` value.
{% endhint %}

{% code title="models/users.js" %}

```javascript
const sequelizeNoUpdateAttributes = require('sequelize-noupdate-attributes');

module.exports = (sequelize, DataTypes) => {
  const { Sequelize } = sequelize;
  sequelizeNoUpdateAttributes(sequelize);
  
  const Users = sequelize.define('users', {
    firstName: {
      type: DataTypes.STRING,
      noUpdate: true,
    },
    lastName: {
      type: DataTypes.STRING,
      noUpdate: true,
    },
    email: {
      type: DataTypes.STRING,
    },
  }, {
    tableName: 'users',
    underscored: true,
    timestamps: false,
    schema: process.env.DATABASE_SCHEMA,
  });

  return Users;
};

```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/woodshop/how-tos/make-field-readonly-with-sequelize.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
