I am starting to swim, and I am trying to create my first API using sails and mysql. I tried to create a table in my mysql console and made the configuration in the configuration.js file and tried to access the API from POSTMAN in the Chrome browser. I get the error below from the sails server. My query has no fields and is not sure whether these fields are standard and are added to the query, and not sure how to automatically create them as part of the table.
error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_BAD_FIELD_ERROR: Unknown column 'message.createdAt' in 'field list'
at Query.Sequence._packetToError (C:\MyApi\node_modules\sails-mysql\node_mod
ules\mysql\lib\protocol\sequences\Sequence.js:48:14)
at Query.ErrorPacket (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\sequences\Query.js:82:18)
at Protocol._parsePacket (C:\MyApi\node_modules\sails-mysql\node_modules\mys
ql\lib\protocol\Protocol.js:271:23)
at Parser.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\pr
otocol\Parser.js:77:12)
at Protocol.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\
protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\
lib\Connection.js:82:28)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10)
at TCP.onread (net.js:529:21)
--------------------
at Protocol._enqueue (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\Protocol.js:135:48)
at PoolConnection.Connection.query (C:\MyApi\node_modules\sails-mysql\node_m
odules\mysql\lib\Connection.js:185:25)
at __FIND__ (C:\MyApi\node_modules\sails-mysql\lib\adapter.js:836:20)
at afterwards (C:\MyApi\node_modules\sails-mysql\lib\connections\spawn.js:84
:5)
at C:\MyApi\node_modules\sails-mysql\lib\connections\spawn.js:40:7
at Ping.onPing [as _callback] (C:\MyApi\node_modules\sails-mysql\node_module
s\mysql\lib\Pool.js:94:5)
at Ping.Sequence.end (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\l
ib\protocol\sequences\Sequence.js:96:24)
at Ping.Sequence.OkPacket (C:\MyApi\node_modules\sails-mysql\node_modules\my
sql\lib\protocol\sequences\Sequence.js:105:8)
at Protocol._parsePacket (C:\MyApi\node_modules\sails-mysql\node_modules\mys
ql\lib\protocol\Protocol.js:271:23)
at Parser.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\pr
otocol\Parser.js:77:12)
at Protocol.write (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\lib\
protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\MyApi\node_modules\sails-mysql\node_modules\mysql\
lib\Connection.js:82:28)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
Details: Error: ER_BAD_FIELD_ERROR: Unknown column 'message.createdAt' in 'fiel
d list'
but I get the above error, below is my table.
mysql> desc message
-> ;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| name | varchar(20) | YES | | NULL | |
| id | int(4) | NO | PRI | NULL | auto_increment |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.03 sec)
and I have the following code in the message.js model
module.exports = {
connection: 'someMysqlServer',
attributes: {
name: { type: 'string',
required: true}
}
};
source
share