I'm trying to update data in a nodejs application. I tested it with postman.
My developing steps was was:
Getting data with id: 10 from DB (MySQL) to update >> Unhandled rejection SequelizeDatabaseError: Query was empty
I recognised, I use wrong id, so I changed to a correct one:50 >> Some other error
It seems to me, I can get the valid data just one time, after I can not reach it... Full stacktrace:
Unhandled rejection SequelizeDatabaseError: Query was empty
at Query.formatError (C:\Users\bla_bla_bla\Documents\work\_nodejs\parentfolder\application\application\node_modules\sequelize\lib\dialects\mysql\query.js:223:16)
at Query.connection.query [as onResult] (C:\Users\bla_bla_bla\Documents\work\_nodejs\parentfolder\application\application\node_modules\sequelize\lib\dialects\mysql\query.js:55:23)
at Query.Command.execute (C:\Users\bla_bla_bla\Documents\work\_nodejs\parentfolder\application\application\node_modules\mysql2\lib\commands\command.js:30:12)
at Connection.handlePacket (C:\Users\bla_bla_bla\Documents\work\_nodejs\parentfolder\application\application\node_modules\mysql2\lib\connection.js:515:28)
at PacketParser.onPacket (C:\Users\bla_bla_bla\Documents\work\_nodejs\parentfolder\application\application\node_modules\mysql2\lib\connection.js:94:16)
at PacketParser.executeStart (C:\Users\bla_bla_bla\Documents\work\_nodejs\parentfolder\application\application\node_modules\mysql2\lib\packet_parser.js:77:14)
at Socket.<anonymous> (C:\Users\bla_bla_bla\Documents\work\_nodejs\parentfolder\application\application\node_modules\mysql2\lib\connection.js:102:29)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20
Ideas?
Note
My problem is not related to model-DB syncronisation. These are syncronised, because I have a case - the first calling - when I can update the object! But if I test that id twice, third etc... I getting this error. So, if these are nor synconised, then I could not update the obejct in the first time neither
UPDATE
After debbing a day, I just recognised, the second and the third time the sequlize making empty SQL query. Below the code snippets:
The good SQL update:
Executing (default): UPDATE `cardModules` SET `field1`='xxxxxxxx',`field2`='xxxxxxxxxx',`field3`='MEDIUM',`field4`=false,`field5`=false WHERE `id` = 43
The bad SQL update:
Executing (default):
The question is: why does Sequlize this?
Number of hours I just recognised the problem. If the sequlize don't find any difference in the DB values and the updateable values, then will generate an empty SQL string and want to execute this. So becaues of this the same sequlize throws this Query was empty message.
So if there is no changes but you want to update, you will get this error.
I handle this problem to check the error message like:
if (err.message == 'Query was empty'){
console.log('There is no changes in the update, lets continue the progress...');
next();
}