Hello,
I am trying to connect LoopBack with an existing mysql database and create REST APIs for a table called country. I have added the db connection in datasource.json and have the following model defined in my models.json.
"country": {
"properties": {
"country_id": {
"type": "number"
},
"country_name": {
"type": "string"
},
"country_code": {
"type": "string"
},
"country_status": {
"type": "number"
}
},
"public": true,
"dataSource": "mysql"
}
When I try to GET countries, I get the following error. I do not have an "id" field in the country table nor is it defined in the models.json. Appreciate any pointers on this.
"error": {
"name": "Error",
"status": 500,
"message": "ER_BAD_FIELD_ERROR: Unknown column 'id' in 'field list'",
"code": "ER_BAD_FIELD_ERROR",
"errno": 1054,
"sqlState": "42S22",
"index": 0,
"stack": "Error: ER_BAD_FIELD_ERROR: Unknown column 'id' in 'field list'\n at Query.Sequence._packetToError (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:30:14)\n at Query.ErrorPacket (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:82:18)\n at Protocol._parsePacket (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:202:24)\n at Parser.write (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Parser.js:62:12)\n at Protocol.write (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:37:16)\n at Socket.<anonymous> (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Connection.js:72:28)\n at Socket.EventEmitter.emit (events.js:95:17)\n at Socket.<anonymous> (_stream_readable.js:746:14)\n at Socket.EventEmitter.emit (events.js:92:17)\n at emitReadable_ (_stream_readable.js:408:10)\n --------------------\n at Protocol._enqueue (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:110:48)\n at PoolConnection.Connection.query (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Connection.js:165:25)\n at runQuery (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/lib/mysql.js:128:16)\n at /home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/lib/mysql.js:174:7\n at Pool.<anonymous> (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Pool.js:53:14)\n at Handshake.Sequence.end (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:78:24)\n at Handshake.Sequence.OkPacket (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:87:8)\n at Protocol._parsePacket (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:202:24)\n at Parser.write (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Parser.js:62:12)\n at Protocol.write (/home/shibu/loopback-mysql-example/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:37:16)"
}
}
Thanks,
Shibu