# Forestadmin Model: how to apply a auto increment field without manual input

**URL:** <https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429>\
**Category:** Help me!\
**Created:** [December 7, 2020, 8:07am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429 "2020-12-07T08:07:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chumanhhung235](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/chumanhhung235/32/1118_2.png) [@chumanhhung235](https://community.forestadmin.com/u/chumanhhung235)\
**Post date:** [December 7, 2020, 8:07am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429/1 "2020-12-07T08:07:49Z")

</div>

Dear Forestadmin support,

I created a database table with id (identifier) column is auto incremental.  
After install project to Forestadmin, when i create new record, it’s must me input id column still.  
Pls help me: How to apply a auto increment field without manual input

Thanks & Regards!  
Hung Chu - Corp IT Head

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 7, 2020, 8:28am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429/2 "2020-12-07T08:28:31Z")

</div>

HI @chumanhhung235 👋 thank you for your report.

Can you send me the generated model and more information of your stack please?

---

<div class="post-metadata">

**Author:** ![chumanhhung235](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/chumanhhung235/32/1118_2.png) [@chumanhhung235](https://community.forestadmin.com/u/chumanhhung235)\
**Post date:** [December 7, 2020, 8:39am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429/3 "2020-12-07T08:39:33Z")

</div>

> [@Arnaud\_Moncel](#):
>
> more

Hi @Arnaud_Moncel, thanks for your support quick, i description details below:  
#1: i setting mysql as image:

 ![Screen Shot 2020-12-07 at 3.29.53 PM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/9/93c41238801a70eec5d413d55fcc5266bb7ad4ce.png)  
#2: after generated:  
 ![Screen Shot 2020-12-07 at 3.30.47 PM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/0057776afb15520fc5957b00a165ff33d7d8ff0d.png)  
#3: my expectation:  
 ![Screen Shot 2020-12-07 at 3.35.12 PM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/05951ecf943801365577666141c91b98961a8d64.png)

pls help me.

Thanks & Regards!  
Hung Chu - Corp IT Head

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 7, 2020, 10:08am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429/4 "2020-12-07T10:08:18Z")

</div>

We experienced an issue on non named `id` auto increment primary key.  
I have created a bug report to our dev team.

I have a workaround while it’s being fixed.

On your `.forestadmin-schema.json` you can set your field like this

```javascript
{
      "field": "cdtId",
      "type": "Number",
      "defaultValue": null,
      "enums": null,
      "integration": null,
      "isFilterable": true,
      "isPrimaryKey": true,
      "isReadOnly": true, // this is the change
      "isRequired": false, // here to 
      "isSortable": true,
      "isVirtual": false,
      "reference": null,
      "inverseOf": null,
      "validations": [] // make sure this is empty
    }

```

And set your `NODE_ENV` to something deferent than dev, to avoid the schema re-generation.

---

<div class="post-metadata">

**Author:** ![chumanhhung235](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/chumanhhung235/32/1118_2.png) [@chumanhhung235](https://community.forestadmin.com/u/chumanhhung235)\
**Post date:** [December 7, 2020, 10:19am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429/5 "2020-12-07T10:19:25Z")

</div>

Thank for your quick reply:

> I have created a bug report to our dev team

=\> hope receiving good news messages soon.

> On your `.forestadmin-schema.json` you can set your field like this

=\> sorry, where is file .forestadmin-schema.json?  
i’m developing on Local, not on production.

Thanks & Best Regards!  
Hung Chu - Corp IT Head

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 7, 2020, 10:36am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429/6 "2020-12-07T10:36:47Z")

</div>

The `.forestadmin-schema.json` is at the root of your project.

I have missed some change sorry.

Make sur you field is like this on your model

```javascript
cdt: {
  type: DataTypes.INTEGER,
  primaryKey: true,
  autoIncrement: true,
}

```

---

<div class="post-metadata">

**Author:** ![chumanhhung235](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/chumanhhung235/32/1118_2.png) [@chumanhhung235](https://community.forestadmin.com/u/chumanhhung235)\
**Post date:** [December 7, 2020, 10:44am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429/7 "2020-12-07T10:44:59Z")

</div>

Hi @Arnaud_Moncel

i added:

> autoIncrement: true,

it works. I resovled the problem.

Thank you so much!  
Hung Chu - Corp IT Head

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 7, 2020, 10:48am UTC](https://community.forestadmin.com/t/forestadmin-model-how-to-apply-a-auto-increment-field-without-manual-input/1429/8 "2020-12-07T10:48:22Z")

</div>

Ok nice 👍.  
I will keep you update when a fix have been released.
