waterline-model.create – primaryKey

我有以下模型与主键ID:

attributes: { id: { type: 'integer', autoIncrement: true, primaryKey: true, unique: true }, name: { type: 'string', unique: true, required: true }, } 

我正在创build模型如下:

 var model = { id: undefined, name: 'name', }; 

waterlinemodel.create(model).exec(function(error,result){});

但它会抛出错误: Error(E_UNKNOWN)遇到一个意外的错误]详细信息:错误:列“id”中的空值违反非空约束

由于“id”是主键,水线不应该看“id”属性的值。

如何解决这个错误? 我不想删除'id',因为我已经为模型创build了value对象,并且它包含了model的所有属性。我正在根据需要设置value对象的属性。 我不需要为创build设置id属性。

我有完全相同的问题,特别是configuration为使用PostgreSQL的模型。 将其设置为磁盘或内存时,将创build资源,但使用postgresql时,不会使用非空约束错误创build资源。

无论是否设置autoPK: true ,都不设置autoPK: true 。 即使使用autoPK:false设置模型上的id属性也不起作用。

正如文档所述:

 Will set the primary key of the record. This should be used when autoPK is set to false. attributes: { uuid: { type: 'string', primaryKey: true, required: true } } 

您需要在模型上设置autoPK : false

链接到文档: https : //github.com/balderdashy/waterline-docs/blob/master/models.md#primarykey