When setting up sails models to use an existing MySql database with string primary keys (PK), the PK is no longer generated automatically.
Am I missing something or do I have to implement the PK generation in beforeCreate
? If I were to implement the PK generation, I'm not sure how to avoid having key collisions with the existing keys from the legacy db.
Calling Cat.create().exec(console.log)
throws the following error:
Invalid attributes sent to User:
• id
• `undefined` should be a string (instead of "null", which is a object)
• "required" validation rule failed for input: null
The model has the following code:
module.exports = {
connection: 'laraschMysql',
schema: true,
identity: 'Contest',
tableName: 'Contest',
migrate: 'safe',
autoPK: false,
autoCreatedAt: false,
autoUpdatedAt: false,
autoUpdatedAt: false,
attributes: {
id: {
type: 'string', //varchar(255) in the db
autoIncrement:true, // not working?
primaryKey: true,
required: true
}
}
Put more generally: What are the usual problems / stumbling blocks / issues when using a legacy database with a new sails application?
Are there any good guides ( the sails documentation doesn't seem to cover the subject too thoroughly ) to setting up a legacy db with sails?