Sails项目 - mysql连接'错误:一致性违规'

时间:2017-07-07 09:38:24

标签: mysql model sails.js sails-permissions

我创建了一个新的sails项目并安装了sails-permission。首先,它运作良好。在创建与Mysql的连接并且确定了sails后,它会抛出错误

error: Error: Consistency violation: A model (`passport`) references a 

datastore which cannot be found ('mysql'). If this model definition has an explicit connection property, check that it is spelled correctly. If not, check your default connection (usually located in config/models.js).

模型passport.js位于node_modules/sails-permission/api/models

配置/ connections.js

 mysql: {
    module    : 'sails-mysql',
    host      : '127.0.0.1',
    port      :  3306,
    user      : 'review',
    password  : 'review',
    database  : 'reviews'
  },

配置/ models.js

module.exports.models = {
  connection: 'mysql',
  migrate: 'alter'
};

node_modules /帆的许可/ API /模型

var bcrypt = require('bcryptjs');

function hashPassword (passport, next) {
  var config = sails.config.auth.bcrypt;
  var salt = config.salt || config.rounds;
  if (passport.password) {
    bcrypt.hash(passport.password, salt, function (err, hash) {
      if (err) {
        delete passport.password;
        sails.log.error(err);
        throw err;
      }
      passport.password = hash;
      next(null, passport);
    });
  }
  else {
    next(null, passport);
  }
}

  var Passport = {
  attributes: {

    password: { type: 'string', minLength: 8 },
    provider   : { type: 'alphanumericdashed' },
    identifier : { type: 'string' },
    tokens     : { type: 'json' },
    user: { model: 'User', required: true },

    validatePassword: function (password, next) {
      bcrypt.compare(password, this.password, next);
    }

  },
  beforeCreate: function (passport, next) {
    hashPassword(passport, next);
  },
  beforeUpdate: function (passport, next) {
    hashPassword(passport, next);
  }
};

module.exports = Passport;

1 个答案:

答案 0 :(得分:2)

这是因为sails-mysql更新。 [https://github.com/balderdashy/sails-mysql/pull/328/files]

module更改为

中的adapter
config/connection.js

mysql: {
    adapter    : 'sails-mysql',
    host      : '127.0.0.1',
    port      :  3306,
    user      : 'review',
    password  : 'review',
    database  : 'reviews'
  },