1

我已经用谷歌搜索了很多,并查看了堆栈溢出的其他解决方案,但没有发现任何可以解决我的问题的方法。定义模型以使用 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"
  }, ...

关于如何解决这个问题有什么建议吗?

4

2 回答 2

2

在 v0.10 中,可以在models.js上定义连接名称,而在connections.js上配置

模型.js

 connection: 'someMysqlServer'

连接.js

 someMysqlServer: {
    adapter : 'sails-mysql',
    host    : 'localhost',
    user    : '',
    password: '', 
    database: ''
  }
于 2014-04-04T10:04:29.357 回答
0

将默认的 adapters.js 文件 mysql 适配器对象从myLocalMySQLDatabase更改为mysql似乎可以修复它。不知道为什么他们更改了 mysql 适配器对象的名称,但我们现在可以开始了。

于 2014-04-03T15:02:42.177 回答