我正在使用sails @ beta。

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

未检测到验证,直到下次重启'sails's服务器,然后我收到此输出:

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
        }
    }
}
.

有帮助吗?

解决方案

这是风帆中的一个错误,它是固定的。谢谢每个人

其他提示

您需要将数据库从默认磁盘数据库更改为您选择的数据库。 我正面临着类似的问题,并将数据库从“磁盘”更改为“mongodb”修复了我的问题。 似乎默认数据库无法强制执行唯一的约束。

我希望它解决您的问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top