I'm trying to send null to my MySQL database using Node.JS:
con.query("INSERT INTO Routes (routeTrigger) VALUES ( " + null + " )", {title: 'test'}, function(err, result) {
if (err) throw err;
});
But when looking in the database, the updated value reads 'null'. The database's NULL is supposed to read NULL. If I send capital NULL instead, that doesn't even work (in Node.JS). If I send 'NULL' it sends the string "NULL", and not the database's NULL.
解决方案
JavaScript's null is not the same as SQL's Null. You want (in your case, using raw SQL strings) a string:
con.query("INSERT INTO Routes (routeTrigger) VALUES ( null )", {title: 'test'}, function(err, result) {
if (err) throw err;
});
But note that that creates a row that's entirely null. Which is possible, but it's unlikely what you want.
What are you actually trying to do?