当设置sails模型以使用带有字符串主键(PK)的现有MySql数据库时,PK不再自动生成。我错过了什么还是我必须在 PK 生成中实现beforeCreate
?如果我要实现 PK 生成,我不确定如何避免与遗留数据库中的现有密钥发生密钥冲突。
调用Cat.create().exec(console.log)
会引发以下错误:
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
该模型具有以下代码:
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
}
}
更笼统地说:将旧数据库与新的 Sails 应用程序一起使用时,常见的问题/绊脚石/问题是什么?
是否有任何好的指南(sails 文档似乎没有完全涵盖该主题)来设置带有sails 的遗留数据库?