在下一个sailsjs服务器重置之前,未检测到水线唯一验证

时间:2014-04-10 22:52:40

标签: express sails.js waterline

我正在使用sails @ beta。

我正在尝试创建下面的几个Room模型(参见定义),问题是我可以成功创建具有相同属性“name”的Room模型,尽管属性“name”具有唯一的验证。

在下次重新启动'sails'服务器之前未检测到验证,然后我收到此输出:

C:\eMali_dev\server>sails lift

info: Starting app...

Express midleware for passport
Waterline encountered a fatal error when trying to perform the `alter` auto-migration strategy.
In a couple of seconds, the data (cached in memory) will be logged to stdout.
(a failsafe put in place to preserve development data)

In the mean time, here's the error:

Error (E_UNKNOWN) :: Encountered an unexpected error:
MongoError: E11000 duplicate key error index: eMali_beta_dev.room.$name_1  dup key: { : "e1" }
Details:
{ error: 'E_UNKNOWN',
  summary: 'Encountered an unexpected error',
  status: 500,
  raw: 'MongoError: E11000 duplicate key error index: eMali_beta_dev.room.$name_1  dup key: { : "e1" }' }


================================
Data backup:
================================

[ { name: 'e1',
    center: '53471e2318b931dc1b69f3a8',
    min_age: 1,
    max_age: 6,
    createdAt: Fri Apr 11 2014 00:41:39 GMT+0200 (W. Europe Summer Time),
    updatedAt: Fri Apr 11 2014 00:41:39 GMT+0200 (W. Europe Summer Time),
    _id: { _bsontype: 'ObjectID', id: 'SG\u001e#\u001811Ü\u001bióc' } },
  { name: 'e2',
    center: '53471e2318b931dc1b69f3a8',
    min_age: 1,
    max_age: 7,
    createdAt: Fri Apr 11 2014 00:41:39 GMT+0200 (W. Europe Summer Time),
    updatedAt: Fri Apr 11 2014 00:41:39 GMT+0200 (W. Europe Summer Time),
    _id: { _bsontype: 'ObjectID', id: 'SG\u001e#\u001811Ü\u001bióª' } },
  { name: 'e1',
    center: '53471e2318b931dc1b69f3a8',
    min_age: 1,
    max_age: 6,
    createdAt: Fri Apr 11 2014 00:41:39 GMT+0200 (W. Europe Summer Time),
    updatedAt: Fri Apr 11 2014 00:41:39 GMT+0200 (W. Europe Summer Time),
    _id: { _bsontype: 'ObjectID', id: 'SG\u001e#\u001811Ü\u001bió«' } } ]
error: A hook (`orm`) failed to load!

房间型号:

module.exports = {

    schema: true,

    attributes: {

        name: {
            type: 'string',
            required: true,
            unique: true,
            minLength: 3
        },

        center: {
            model: 'center'
        },

        min_age: {
            type: 'integer',
            required: true
        },

        max_age: {
            type: 'integer',
            required: true
        }
    }
}

2 个答案:

答案 0 :(得分:1)

这是帆的一个错误,它已修复。谢谢大家

答案 1 :(得分:0)

您需要将数据库从默认磁盘数据库更改为您选择的数据库。 我遇到了类似的问题,并从"磁盘" to" MongoDB"解决了我的问题。 似乎默认数据库无法强制执行唯一约束。

我希望它能解决你的问题。