使用node.js在MySQL中创建表时出错



我在MySQL中创建表时遇到问题,该表返回ER_Parse_Error。我一直在浏览表格,但找不到错误的原因,如果有人能看一看,我真的很感激。下表:桌子

下面是它返回的错误:返回错误。

编辑:这是文本中的表格:

//Cian
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "******"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "CREATE TABLE Order ( order_id INTEGER(10) AUTO_INCREMENT PRIMARY KEY, order_description VARCHAR(255),order_date DATETIME,order_state VARCHAR(255),order_report_id integer(10))";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Table created");
});
});

这是文本中的错误:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Order ( order_id INTEGER(10) AUTO_INCREMENT PRIMARY KEY, order_description VARCH' at line 1
at Query.Sequence._packetToError (H:node_modulesmysqllibprotocolsequencesSequence.js:47:14)
at Query.ErrorPacket (H:node_modulesmysqllibprotocolsequencesQuery.js:77:18)
at Protocol._parsePacket (H:node_modulesmysqllibprotocolProtocol.js:278:23)
at Parser.write (H:node_modulesmysqllibprotocolParser.js:76:12)
at Protocol.write (H:node_modulesmysqllibprotocolProtocol.js:38:16)
at Socket.<anonymous> (H:node_modulesmysqllibConnection.js:91:28)
at Socket.<anonymous> (H:node_modulesmysqllibConnection.js:502:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
--------------------
at Protocol._enqueue (H:node_modulesmysqllibprotocolProtocol.js:144:48)
at Connection.query (H:node_modulesmysqllibConnection.js:200:25)
at Handshake.<anonymous> (H:Cloudcreate_tables.js:120:6)
at Handshake.<anonymous> (H:node_modulesmysqllibConnection.js:502:10)
at Handshake._callback (H:node_modulesmysqllibConnection.js:468:16)
at Handshake.Sequence.end (H:node_modulesmysqllibprotocolsequencesSequence.js:83:24)
at Handshake.Sequence.OkPacket (H:node_modulesmysqllibprotocolsequencesSequence.js:92:8)
at Protocol._parsePacket (H:node_modulesmysqllibprotocolProtocol.js:278:23)
at Parser.write (H:node_modulesmysqllibprotocolParser.js:76:12)
at Protocol.write (H:node_modulesmysqllibprotocolProtocol.js:38:16)

由于MySQL对MySQL保留关键字不区分大小写,因此OrderOrder相同,Order是MySQL保留关键字,因此您无法通过订单名称创建这样的表。

所以,如果你想用这个名字创建你的表,那么就使用这样的东西:

CREATE TABLE test.Order (order_id INTEGER(10) AUTO_INCREMENT PRIMARY KEY,  order_description VARCHAR(255), order_date DATETIME, order_state VARCHAR(255), order_report_id integer(10));

这里的test是一个测试数据库,我想在这里创建我的表。

相关内容

  • 没有找到相关文章

最新更新