node.js - sails-mysql: ER_NO_DB_ERROR: No database selected -
when trying use sails-mysql er_no_db_error: no database selected
exception. though followed instructions able find closely possible. looked related issues:
- sailsjs - how use mysql
- https://github.com/balderdashy/sails/issues/632
- http://dustinbolton.com/error-er_no_db_error-no-database-selected/
nothing seemed far.
this doing:
i started out fresh project:
sails new sql-test cd sql-test
installed sails-mysql
sudo npm install sails-mysql
i changed config:
// config/adapters.js module.exports.adapters = { 'default': 'mysql', mysql: { module : 'sails-mysql', host : 'localhost', port : 3306, user : 'root', password : 'supersecret', database : 'testdb' } };
created model:
// api/models/user.js module.exports = { attributes: { name: 'string' } };
and when try run project's root:
sails lift
i following:
logic error in mysql orm. { [error: er_no_db_error: no database selected] code: 'er_no_db_error', index: 0 } error: hook failed load: orm (error: er_no_db_error: no database selected) error: error encountered while loading sails core! error: error: er_no_db_error: no database selected @ query.sequence._packettoerror (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/sequence.js:32:14) @ query.errorpacket (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/query.js:82:18) @ protocol._parsepacket (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/protocol.js:172:24) @ parser.write (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/parser.js:62:12) @ protocol.write (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/protocol.js:37:16) @ socket.ondata (stream.js:51:26) @ socket.eventemitter.emit (events.js:117:20) @ socket.<anonymous> (_stream_readable.js:746:14) @ socket.eventemitter.emit (events.js:92:17) @ emitreadable_ (_stream_readable.js:408:10) @ emitreadable (_stream_readable.js:404:5) @ readableaddchunk (_stream_readable.js:165:9) @ socket.readable.push (_stream_readable.js:127:10) @ tcp.onread (net.js:526:21) -------------------- @ query.sequence (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/sequence.js:15:20) @ new query (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/query.js:12:12) @ function.connection.createquery (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/connection.js:48:10) @ connection.query (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/connection.js:100:26) @ __describe__ (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/lib/adapter.js:121:20) @ afterwards (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/lib/adapter.js:571:7) @ handshake._callback (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/lib/adapter.js:549:9) @ handshake.sequence.end (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/sequence.js:66:24) @ handshake.sequence.okpacket (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/sequence.js:75:8) @ protocol._parsepacket (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/protocol.js:172:24) @ parser.write (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/parser.js:62:12) @ protocol.write (/home/tster/documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/protocol.js:37:16) @ socket.ondata (stream.js:51:26) @ socket.eventemitter.emit (events.js:117:20) @ socket.<anonymous> (_stream_readable.js:746:14) @ socket.eventemitter.emit (events.js:92:17) @ emitreadable_ (_stream_readable.js:408:10) @ emitreadable (_stream_readable.js:404:5) @ readableaddchunk (_stream_readable.js:165:9) @ socket.readable.push (_stream_readable.js:127:10) @ tcp.onread (net.js:526:21)
additional information:
- sails v0.9.13
- sails-mysql (v0.9.9)
- mysql v14.14 distrib 5.5.34, debian-linux-gnu (x86_64) using readline 6.2
- i can connect the database via command line.
- i able connect , query database when using node-mysql
could give me advice? missing something? else should check out?
i hit same problem. in order work, had add adapter configuration information model, e.g. /api/models/user.js:
module.exports = { adapter: 'mysql', config: { host: 'localhost', user: 'user', port:'3306', // psst.. can put password in config/local.js instead // don't inadvertently push if you're using version control password: 'secret', database: 'sailstest' }, attributes: { firstname: 'string' } };
see docs:
http://sailsjs.org/#!documentation/models
i had add /api/controllers/usercontroller.js manually, generate function did not add on app, although did add on previous test app made.
update:
install sails.js beta better functionality.
npm install sails@beta -g
not config work expected (under config/connections.js), orm features support associations, not supported in 0.9 release.
Comments
Post a Comment