Sails名称类型返回undefined而不是字符串

时间:2018-07-07 01:55:58

标签: sails.js

我的Sails Seed已配置为在模型下放置name属性的字符串,但是它使我的应用程序崩溃了。

error: Bootstrap encountered an error: (see below)
error:
error: { UsageError: Invalid initial data for new records.
Details:
  Could not use one of the provided new records: Missing value for required attribute `name`.  Expected a string, but instead, got: undefined
 [?] See https://sailsjs.com/support for help.
    at Object.module.exports.bootstrap (/Users/adarian/learn-sails/config/bootstrap.js:63:14)
  cause:
   { UsageError: Invalid initial data for new records.
   Details:
     Could not use one of the provided new records: Missing value for required attribute `name`.  Expected a string, but instead, got: undefined
    [?] See https://sailsjs.com/support for help.
       at Object.module.exports.bootstrap (/Users/adarian/learn-sails/config/bootstrap.js:63:14)
     name: 'UsageError',
     code: 'E_INVALID_NEW_RECORDS',
     details:
      'Could not use one of the provided new records: Missing value for required attribute `name`.  Expected a string, but instead, got: undefined' },
  isOperational: true,
  code: 'E_INVALID_NEW_RECORDS',
  details:
   'Could not use one of the provided new records: Missing value for required attribute `name`.  Expected a string, but instead, got: undefined' }

由于种子文件如下所示,该如何解决。

 /**
 * Sails Seed Settings
 * (sails.config.seeds)
 *
 * Configuration for the data seeding in Sails.
 *
 * For more information on configuration, check out:
 * http://github.com/frostme/sails-seed
 */
module.exports.seeds = {
  user: [
    {
      name: "John Wayne",
      email: 'johnnie86@gmail.com',
      avatar: 'https://randomuser.me/api/portraits/men/83.jpg',
      location: 'Mombasa',
      bio: 'Spends most of my time at the beach'
    }
  ]
};

1 个答案:

答案 0 :(得分:2)

我发现问题的原因归因于列出了config/model.js的{​​{1}}文件,而该文件又应该是migrate: 'drop'。我不知道为什么将其设置为migrate: 'alter'是错误的,但是它不能与drop一起使用,而只能与dropsafe一起使用。