我尝试使用sails-mysql适配器0.10.6尝试风帆js版本0.10.0
我创建了两个模型:
Customer.js
module.exports = {
connection: 'someMysqlServer',
attributes: {
name: {
type: 'string'
},
store: {
model: 'Store'
}
}
};
和 Store.js
module.exports = {
connection: 'someMysqlServer',
attributes: {
name: {
type: 'string'
},
customers: {
model: 'Customer',
required: false
}
}
};
当我第一次运行应用程序时,一切都很好,我可以看到它在我的数据库上创建了两个表。但是,当我尝试重新启动应用程序时,我收到此错误:
TypeError: Cannot read property 'schema' of undefined
at __FIND__ (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-mys
ql\lib\adapter.js:808:42)
at afterwards (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-m
ysql\lib\connections\spawn.js:86:5)
at C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-mysql\lib\con
nections\spawn.js:40:7
at Ping._callback (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sai
ls-mysql\node_modules\mysql\lib\Pool.js:81:7)
at Ping.Sequence.end (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\
sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:78:24)
at Ping.Sequence.OkPacket (C:\fray\NodeJs\testingsails10_2\test1001\node_mod
ules\sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:87:8)
at Protocol._parsePacket (C:\fray\NodeJs\testingsails10_2\test1001\node_modu
les\sails-mysql\node_modules\mysql\lib\protocol\Protocol.js:213:24)
at Parser.write (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails
-mysql\node_modules\mysql\lib\protocol\Parser.js:62:12)
at Protocol.write (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sai
ls-mysql\node_modules\mysql\lib\protocol\Protocol.js:37:16)
at Socket.<anonymous> (C:\fray\NodeJs\testingsails10_2\test1001\node_modules
\sails-mysql\node_modules\mysql\lib\Connection.js:75:28)
如果我删除表并重新启动应用程序,它将能够运行并重新创建表,但是当我到达此控制器时,它将不会更进一步。
module.exports = {
add: function(req, res){
var store = {
name: 'strore2'
}
Store.create(store).exec(function(err, result){
Customer.create({name: 'customer1', store: result.id}).exec(function (err1, result1){
return res.json({created: result1, error: err1});
});
});
}
};
并将抛出此错误:
TypeError: Cannot read property 'schema' of undefined
at __CREATE__ (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-m
ysql\lib\adapter.js:386:42)
at afterwards (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-m
ysql\lib\connections\spawn.js:86:5)
at C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-mysql\lib\con
nections\spawn.js:40:7
at Ping._callback (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sai
ls-mysql\node_modules\mysql\lib\Pool.js:81:7)
at Ping.Sequence.end (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\
sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:78:24)
at Ping.Sequence.OkPacket (C:\fray\NodeJs\testingsails10_2\test1001\node_mod
ules\sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:87:8)
at Protocol._parsePacket (C:\fray\NodeJs\testingsails10_2\test1001\node_modu
les\sails-mysql\node_modules\mysql\lib\protocol\Protocol.js:213:24)
at Parser.write (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails
-mysql\node_modules\mysql\lib\protocol\Parser.js:62:12)
at Protocol.write (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sai
ls-mysql\node_modules\mysql\lib\protocol\Protocol.js:37:16)
at Socket.<anonymous> (C:\fray\NodeJs\testingsails10_2\test1001\node_modules
\sails-mysql\node_modules\mysql\lib\Connection.js:75:28)
答案 0 :(得分:1)
这似乎是一个破坏的依赖问题。尝试:
rm -rf node_modules
npm cache clear
npm install
要重新安装所有依赖项,请尝试sails lift
。
此时,您将在项目中本地安装Sails,sails lift
将使用该副本。要在全球风帆安装上执行类似的手术,请执行以下操作:
sudo npm uninstall -g sails
npm cache clear
sudo npm install -g sails
然后在项目中rm -rf node_modules/sails
,以便sails lift
将使用全局安装。