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

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

HI @chumanhhung235 :wave: thank you for your report.

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

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


#2: after generated:

#3: my expectation:

pls help me.

Thanks & Regards!
Hung Chu - Corp IT Head

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

{
      "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.

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

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

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

Hi @Arnaud_Moncel

i added:

autoIncrement: true,

it works. I resovled the problem.

Thank you so much!
Hung Chu - Corp IT Head

2 Likes

Ok nice :+1:.
I will keep you update when a fix have been released.

2 Likes