我已经搜索了相当多的内容,并查看了堆栈溢出的其他解决方案,但没有找到任何解决我问题的方法。在定义模型以使用mysql而不是磁盘时,我收到以下错误
verbose: Registering model `users` in Waterline (ORM) with definition ::
{ identity: 'users',
tableName: 'users',
connections:
[ { pool: true,
connectionLimit: 10,
waitForConnections: true,
adapter: 'sails-mysql' } ],
config:
{ host: 'localhost',
port: 3306,
user: 'root',
password: 'password',
database: 'sailsapp' },
attributes: { name: 'string', email: 'string', phone: 'string' },
globalId: 'users',
introduce: [Function: bound],
obituary: [Function: bound],
publish: [Function: bound],
pluralize: [Function],
room: [Function: bound],
classRoom: [Function],
subscribers: [Function],
publishCreate: [Function: bound],
publishUpdate: [Function: bound],
publishDestroy: [Function: bound],
subscribe: [Function: bound],
unsubscribe: [Function: bound],
adapter: [ 'adhoc_adapter_0' ] }
Logic error in mySQL ORM.
{ [Error: ER_NO_DB_ERROR: No database selected] code: 'ER_NO_DB_ERROR', index: 0 }
error: Hook failed to load: orm (Error: ER_NO_DB_ERROR: No database selected)
verbose: Hooks loaded!
error: Error encountered while loading Sails core!
error: Error: ER_NO_DB_ERROR: No database selected
at Query.Sequence._packetToError (/home/rich/PhpstormProjects/sailsjs/node_modules/sails- mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:32:14)
at Query.ErrorPacket (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:82:18)
at Protocol._parsePacket (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:172:24)
at Parser.write (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:62:12)
at Protocol.write (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:37:16)
at Socket.ondata (stream.js:51:26)
at Socket.EventEmitter.emit (events.js:117:20)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:528:21)
--------------------
at Query.Sequence (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
at new Query (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:12:12)
at Function.Connection.createQuery (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:48:10)
at Connection.query (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:100:26)
at __DESCRIBE__ (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/lib/adapter.js:121:20)
at afterwards (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/lib/adapter.js:571:7)
at Handshake._callback (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:37:9)
at Handshake.Sequence.end (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24)
at Handshake.Sequence.OkPacket (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:75:8)
at Protocol._parsePacket (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:172:24)
at Parser.write (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:62:12)
at Protocol.write (/home/rich/PhpstormProjects/sailsjs/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:37:16)
at Socket.ondata (stream.js:51:26)
at Socket.EventEmitter.emit (events.js:117:20)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:528:21)
我在其他地方读过新版本的sails.js(0.9.16)存在已知错误,其中必须为每个模型指定适配器和配置。我已经完成了,你可以从错误日志中看到,但是我的模型的代码在
之下module.exports = {
adapter: 'mysql',
config: {
host: 'localhost',
port: 3306,
user: 'root',
password: 'password',
database: 'sailsapp'
},
attributes: {
name: 'string',
email: 'string',
phone: 'string'
}
};
我仍然遇到同样的错误。这是我的应用程序的package.json文件
{
"name": "sailsjs",
"private": true,
"version": "0.0.0",
"description": "a Sails application",
"dependencies": {
"sails": "0.9.16",
"grunt": "0.4.1",
"sails-disk": "~0.9.0",
"ejs": "0.8.4",
"optimist": "0.3.4"
},
"scripts": {
"start": "node app.js",
"debug": "node debug app.js"
},
"main": "app.js",
"repository": "",
"author": "",
"license": ""
}
和我的sails-mysql版本的package.json文件
{
"name": "sails-mysql",
"version": "0.9.9",
"description": "MySQL adapter for Sails.js",
"main": "lib/adapter.js",
"scripts": {
"test": "make test"
}, ...
有关于如何解决此问题的任何建议吗?
答案 0 :(得分:2)
在v0.10中,可以在 models.js 上定义连接名称,该名称是在 connections.js
上配置的models.js
connection: 'someMysqlServer'
<强> connections.js 强>
someMysqlServer: {
adapter : 'sails-mysql',
host : 'localhost',
user : '',
password: '',
database: ''
}
答案 1 :(得分:0)
将默认的adapters.js文件mysql适配器对象从myLocalMySQLDatabase
更改为简单mysql
似乎解决了这个问题。不知道为什么他们改变了mysql适配器对象的名称,但我们现在很高兴。