gpt4 book ai didi

javascript - mysql 上的 sails v10.0 遇到未定义的 'schema'

转载 作者:行者123 更新时间:2023-11-29 12:45:08 25 4
gpt4 key购买 nike

我正在尝试使用 sails-mysql 适配器 0.10.6 的 sails 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)

如果我删除表并重新启动应用程序,它将能够运行并重新创建表,但当我到达此 Controller 时不会进一步。

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)

最佳答案

这似乎是一个损坏的依赖关系问题。尝试:

rm -rf node_modules
npm cache clear
npm install

要重新安装所有依赖项,请尝试sails lift

此时,您将在项目中本地安装 Sails,并且 sails lift 将使用该副本。要对您的 global sails 安装执行类似的操作,请执行以下操作:

sudo npm uninstall -g sails
npm cache clear
sudo npm install -g sails

然后在您的项目中添加rm -rf node_modules/sails,以便sails lift 将使用全局安装。

关于javascript - mysql 上的 sails v10.0 遇到未定义的 'schema',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25558153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com