节点Express + Sequelize findAll在空数据库上返回SequelizeDatabaseError

时间:2019-05-15 13:53:13

标签: node.js sqlite express sequelize.js

我正在尝试检索Orders(SQLite)的简单列表(暂时没有where子句)。 我正确配置了节点Express服务器,路由器和模型。我的收藏仍然是空的。 当我尝试路线

router.get('/orders', (req, res) => {
Order.findAll({order: [['updateAt', 'DESC']]})
 .then(orders => {
  res.send(orders);
 })
 .catch(error => {
  res.send({error: error});
 });
});

响应是

{
"error": {
    "name": "SequelizeDatabaseError",
    "parent": {
        "errno": 1,
        "code": "SQLITE_ERROR",
        "sql": "SELECT `id`, `order_num`, `order_date`, `status`, `createdAt`, `updatedAt` FROM `Orders` AS `Order` ORDER BY `Order`.`updateAt` DESC;"
    },
    "original": {
        "errno": 1,
        "code": "SQLITE_ERROR",
        "sql": "SELECT `id`, `order_num`, `order_date`, `status`, `createdAt`, `updatedAt` FROM `Orders` AS `Order` ORDER BY `Order`.`updateAt` DESC;"
    },
    "sql": "SELECT `id`, `order_num`, `order_date`, `status`, `createdAt`, `updatedAt` FROM `Orders` AS `Order` ORDER BY `Order`.`updateAt` DESC;"
}

我没有找到正确的方法来拦截 O(零)订单未找到数据而不会产生错误。

1 个答案:

答案 0 :(得分:1)

检查您的列名。此代码Order.findAll({order: [['updateAt', 'DESC']]})可能是错误的,因为错误消息中的查询表明该列实际上是更新的 d At