0
我正在進行權限管理。我在db中爲admin創建了另一個表並創建了一個數據inf。但是,當我搜索它沒有工作。錯誤:必須包含引用適配器使用的`adapter`鍵
以下是在API /控制器/ AdminController.js代碼
checkUN: function(req, res) {
var name = req.param('name');
Admin.find({
name: name
}).exec(function findOneCB(err, admins) {
// print in terminal correctly
console.log('name:'+name);
if (err) {
// console.log('err');
// did not enter this judgment
// res.redirect('admin/login');
return res.json({
error: 'This user name does not exist'
});
}
// return res.view("user/addUser", {
// admins: admins
// });
});
},
有在終端或瀏覽器console.Then沒有錯誤INF我增加了connection
和tableName
每個車型。
這裏是API /型號編碼/ Admin.js
module.exports = {
connection: 'applicationform',
tableName: 'Admin',
attributes: {
name: {
type: 'string'
},
password: {
type: 'string'
},
email: {
type: 'string'
},
createdAt: {
type: 'datetime',
defaultsTo: function(){ return new Date(); }
},
updatedAt: {
type: 'datetime',
defaultsTo: function(){ return new Date(); }
}
}
};
這裏是終端錯誤INF:
error: In model (admin), invalid connection :: applicationform
error: Must contain anadapter
key referencing the adapter to use.
這是我的配置/ connections.js代碼。
mysql: {
adapter : 'sails-mysql',
host : 'localhost',
port : 3306,
user : 'root',
password : '1',
database : 'applicationform'
},
我不認爲你會得到一個錯誤,但是如果你的查詢沒有找到結果,結果爲空數組 – elssar
謝謝elssar!我弄錯了。 –