您的 sql 语法有误(连接正常)
You have an error in your sql syntax (connection is OK)
我正在使用 Node.js 和 Bookshelf,我是 bookshelf 的新手。我做了一个基本代码但不起作用,我无法保存。
这是代码:
var bookModel = bookshelf.Model.extend({
tablename: 'book'
});
app.get('/addBook/:title/:id', function(req, res) {
if (req.params.title != '' && req.params.id != ''){
bookModel.forge({title: 'test'}).save();
}
我的连接工作正常。
这是错误:
Add book : undefined - 44 Unhandled rejection Error: ER_PARSE_ERROR:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right sy ntax to use
near '(title
) values ('toto')' at line 1
我看到这是一条常见的消息,但我不太明白。我在文档中搜索了更多信息,但没有找到任何对我有帮助的信息。
感谢您的帮助!
属性tablename
应该是tableName
(注意大写'N'):
var bookModel = bookshelf.Model.extend({
tableName: 'book'
});
如果您查看您在评论中发布的 SQL,它是 insert into (title) values (?)
,这是无效的 SQL,因为它缺少目标 table 名称。我用这个线索发现了问题。
我正在使用 Node.js 和 Bookshelf,我是 bookshelf 的新手。我做了一个基本代码但不起作用,我无法保存。
这是代码:
var bookModel = bookshelf.Model.extend({
tablename: 'book'
});
app.get('/addBook/:title/:id', function(req, res) {
if (req.params.title != '' && req.params.id != ''){
bookModel.forge({title: 'test'}).save();
}
我的连接工作正常。
这是错误:
Add book : undefined - 44 Unhandled rejection Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right sy ntax to use near '(
title
) values ('toto')' at line 1
我看到这是一条常见的消息,但我不太明白。我在文档中搜索了更多信息,但没有找到任何对我有帮助的信息。
感谢您的帮助!
属性tablename
应该是tableName
(注意大写'N'):
var bookModel = bookshelf.Model.extend({
tableName: 'book'
});
如果您查看您在评论中发布的 SQL,它是 insert into (title) values (?)
,这是无效的 SQL,因为它缺少目标 table 名称。我用这个线索发现了问题。