将sails模型设置为使用具有字符串主键( PK )的现有MySql数据库时,不再自动生成PK。我是不是遗漏了什么,或者我必须在beforeCreate中实现PK生成?如果我要实现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设置遗留数据库?
发布于 2016-03-22 19:23:47
根据Sails.js文档,整数必须始终是类型:‘autoIncrement’
autoIncrement
将该属性设置为自动增量键。当向模型中添加新记录时,如果未指定此属性的值,则将通过将最新记录的值递增1来生成该记录。注意:指定整数的属性应始终为:‘autoIncrement’类型。此外,请记住,不同数据存储区的支持级别各不相同。例如,MySQL不允许每个表有一个以上的自动递增列。
https://stackoverflow.com/questions/35834273
复制相似问题