Hi, i'm trying to follow the example of auto-migrate, this is my model definition:
{
"name": "NSCustomer",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true,
"mysql": {
"table": "ns_customer"
}
},
"mixins": {
"Timestamp": {
"created_at": "ns_create_date",
"updated_at": "ns_last_sync_date"
}
},
"properties": {
"id_ns_customer": {
"type": "number",
"id": true
},
"ns_create_date": {
"type": "string",
"required": true
},
"ns_last_sync_date": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
I edit the bin/server/auto-migrate.js file to be like this
dataSource.automigrate(['AccessToken', 'ACL', 'RoleMapping', 'Role', 'NSCustomer'], function(err) {
if (err) throw err;
});
The table was created just fine, except for the primary key id_ns_customer not getting Auto-increment, does anyone know why? I checked the model definition of acl and i don't see anywhere that auto-increment needs to be declared.
Thank you.
Try setting "idInjection": false
LoopBack automatically adds an id property to the model if set to true.
I found the propery to set, which is "generated"
Thanks for helping!
For anyone still wondering. Setting generated to true in the id object is what sets auto increment to true.
This is what my id looks like
"id": {
"type": "Number",
"id": 1,
"required": true,
"length": null,
"precision": 10,
"scale": 0,
"generated" : true,
"mysql": {
"columnName": "id",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
}
},
Most helpful comment
For anyone still wondering. Setting generated to true in the id object is what sets auto increment to true.
This is what my id looks like
Link to the docs