我尝试在服务器上使用我的Sails项目。我安装了mysql。当我调用创建用户的请求时,sails不会自动创建表“ User”。
我收到此错误:
sails-hook-sockets :: connected to Sails admin message bus. Sending 500 ("Server Error") response: Error (E_UNKNOWN) :: Encountered an unexpected error : ER_NO_SUCH_TABLE: Table 'mooz.user' doesn't exist at Query.Sequence._packetToError (/home/mooz/api/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14) at Query.ErrorPacket (/home/mooz/api/node_modules/mysql/lib/protocol/sequences/Query.js:83:18) at Protocol._parsePacket (/home/mooz/api/node_modules/mysql/lib/protocol/Protocol.js:271:23) at Parser.write (/home/mooz/api/node_modules/mysql/lib/protocol/Parser.js:77:12) at Protocol.write (/home/mooz/api/node_modules/mysql/lib/protocol/Protocol.js:39:16) at Socket.(/home/mooz/api/node_modules/mysql/lib/Connection.js:92:28) at Socket.EventEmitter.emit (events.js:95:17) at Socket. (_stream_readable.js:710:14) at Socket.EventEmitter.emit (events.js:92:17) at emitReadable_ (_stream_readable.js:382:10) at emitReadable (_stream_readable.js:378:5) at readableAddChunk (_stream_readable.js:143:7) at Socket.Readable.push (_stream_readable.js:113:10) at TCP.onread (net.js:511:21) -------------------- at Protocol._enqueue (/home/mooz/api/node_modules/mysql/lib/protocol/Protocol.js:135:48) at PoolConnection.Connection.query (/home/mooz/api/node_modules/mysql/lib/Connection.js:197:25) at __FIND__ (/home/mooz/api/node_modules/sails-mysql/lib/adapter.js:836:20) at afterwards (/home/mooz/api/node_modules/sails-mysql/lib/connections/spawn.js:84:5) at /home/mooz/api/node_modules/sails-mysql/lib/connections/spawn.js:40:7 at Ping.onPing [as _callback] (/home/mooz/api/node_modules/mysql/lib/Pool.js:94:5) at Ping.Sequence.end (/home/mooz/api/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24) at Ping.Sequence.OkPacket (/home/mooz/api/node_modules/mysql/lib/protocol/sequences/Sequence.js:105:8) at Protocol._parsePacket (/home/mooz/api/node_modules/mysql/lib/protocol/Protocol.js:271:23) at Parser.write (/home/mooz/api/node_modules/mysql/lib/protocol/Parser.js:77:12) at Protocol.write (/home/mooz/api/node_modules/mysql/lib/protocol/Protocol.js:39:16) at Socket. (/home/mooz/api/node_modules/mysql/lib/Connection.js:92:28) at Socket.EventEmitter.emit (events.js:95:17) at Socket. (_stream_readable.js:710:14) at Socket.EventEmitter.emit (events.js:92:17) at emitReadable_ (_stream_readable.js:382:10) at emitReadable (_stream_readable.js:378:5) at readableAddChunk (_stream_readable.js:143:7) at Socket.Readable.push (_stream_readable.js:113:10) at TCP.onread (net.js:511:21) Details: Error: ER_NO_SUCH_TABLE: Table 'mooz.user' doesn't exist
这是我的模型User.js
var Waterline = require('waterline'); // Define your collection (aka model) var User = Waterline.Collection.extend({ attributes: { connection:'mysql', tableName:'user', id: { type: 'string', required: true, primaryKey: true, unique: true }, username: { type: 'string', required: true } } });
我的model.js:
module.exports.models = { connection: 'mysql', migrate: 'safe' };
我的connection.js:
module.exports.connections = { mysql: { adapter : 'sails-mysql', host : 'localhost', user : 'user', port : 3306, password : 'test', database : 'mooz' } };
还有我的userController
module.exports = { createUser: function(req, res){ var params = req.params.all(); User.create({username: params.username, id: params.id}).exec(function createUser(err,created){ return res.json({ notice: 'Created user ' + params.username }); }); } };
我不明白为什么风帆无法自动创建桌子,我忘记了什么吗?有什么命令要做吗?
谢谢。
编辑:与开发环境解决
您可以尝试再次设置migrate: 'alter'
model.js sails lift
。