首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sails 1.0 -sails-用于开发/测试的磁盘和用于生产的sails-mongo

Sails 1.0 -sails-用于开发/测试的磁盘和用于生产的sails-mongo
EN

Stack Overflow用户
提问于 2018-03-29 01:24:28
回答 1查看 638关注 0票数 1

在Sails1.0中,我尝试使用sails-mongo进行开发和生产,使用sails-disk进行测试。在1.0版本之前,我可以这样做,但现在我收到一个错误:

代码语言:javascript
复制
error: Error: In model 'user', primary key 'id' must have either
 'required' or 'autoIncrement' set.

我的代码:

代码语言:javascript
复制
module.exports = {
  attributes: {
    createdAt: { type: 'number', autoCreatedAt: true },
    updatedAt: { type: 'number', autoUpdatedAt: true },
    id: { type: 'string', columnName: '_id' }, //<---- error Here!

    name: {
      type: 'string',
      required: true
    },
    ......
}

我可以做一些变通方法来使它工作吗?

EN

回答 1

Stack Overflow用户

发布于 2018-03-29 15:39:56

id字段中添加required规则。

代码语言:javascript
复制
module.exports = {
  attributes: {
    createdAt: { type: 'number', autoCreatedAt: true },
    updatedAt: { type: 'number', autoUpdatedAt: true },
    id: { type: 'string', columnName: '_id', required: true }, //<---- Add it here

    name: {
      type: 'string',
      required: true
    },
    ......
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49540671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档