我有以下带有主键 ID 的模型:
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey: true,
unique: true
},
name: {
type: 'string',
unique: true,
required: true
},
}
我正在创建如下模型:
var model = {
id: undefined,
name: 'name',
};
waterlinemodel.create(model).exec(function(error, result) {});
但它抛出以下错误: Error (E_UNKNOWN) Encountered an unexpected error] 详细信息:错误:“id”列中的空值违反了非空约束
因为“id”是主键,水线不应查看“id”属性的值。
如何解决这个错误?我不想删除“id”,因为我已经为模型创建了值对象并且它包含模型的所有属性。我正在根据需要设置值对象属性。我不需要为创 build 置 id 属性。
最佳答案
我遇到了完全相同的问题,尤其是配置为使用 postgresql 的模型。将其设置为磁盘或内存时,将创建资源,但使用 postgresql 时,不会创建资源,并出现非空约束错误。
无论我是否设置 autoPK: true
都不会设置 id。即使使用 autoPK:false
在模型上设置 id 属性也不起作用。
关于database - waterline-model.create - primaryKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29533190/