Sails.JS will not lift without autoIncrement being set to true for my model's id attribute

204 Views Asked by At

Unfortunately this table uses id as a varchar(255) and there is no column used as an auto-incrementing id. For my purposes I cannot change that. The id is a string and there's no way around that for me.

module.exports = {

  tableName: 'report_config',
  attributes: {

    id: { type: 'string', autoIncrement: true },
    APP_NAME: {type: 'string' },
    REPORT_NAME: {type: 'string'},
    REPORT_DESCRIPTION: {type: 'string'},
    USERNAME: {type: 'string'},
    CONTACT_NAME: {type: 'string'},
  },

};

When I go to the route for this model (no controller or view has been defined yet, just the default controller file that is created) I am presented with 30 entries. I understand this is due to the blueprints feature which is pretty handy.

However, if I remove autoIncrement from id I get an error when trying to lift the application:

error: Could not tear down the ORM hook.  Error details: Error: Invalid data store identity. No data store exist with that identity.

I commented out the createdAt, updatedAt, and id attributes in models.js and I don't know where else this default would be set.

What am I doing wrong here?

1

There are 1 best solutions below

0
S16 On

The solution is to make sure that id is set to required: true.