渲染使节点应用程序崩溃,错误为“ SequelizeDatabaseError:关系“订单”不存在”

时间:2018-10-19 18:29:38

标签: node.js express ejs

渲染页面时,节点应用程序崩溃使我感到困惑。这是代码:

router.get("/",  async (req, res) => {

    console.log("BEFORE orders is filled with data");
    orders = Order.findAll({});
    console.log("orders is filled with data", orders);
    res.render('../views/main_view.ejs', {item_list: orders, partial_view: '../views/order/item_list.ejs'}, function(err, html){
        if (err) {
            console.log("render order error", err.message);
        } else {
            console.log('No render error');
            res.send(html);
        };
    });

});

这是控制台消息:

BEFORE orders is filled with data
orders is filled with data Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
No render error
Executing (default): SELECT "id", "order_no", "customer_name", "amount_rmb", "amount_crypto", "note", "order_datetime", "order_status", "payment_rcvd", "paid_at", "crypto_currency", "customer_id", "last_updated_by_id", "createdAt", "updatedAt" FROM "orders" AS "order";
[nodemon] app crashed - waiting for file changes before starting

......

{ SequelizeDatabaseError: relation "orders" does not exist
    at Query.formatError (C:\d\code\js\mbot\node_modules\sequelize\lib\dialects\postgres\query.js:363:16)
    at query.catch.err (C:\d\code\js\mbot\node_modules\sequelize\lib\dialects\postgres\query.js:86:18)
    at tryCatcher (C:\d\code\js\mbot\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\d\code\js\mbot\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (C:\d\code\js\mbot\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (C:\d\code\js\mbot\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\d\code\js\mbot\node_modules\bluebird\js\release\promise.js:690:18)
    at _drainQueueStep (C:\d\code\js\mbot\node_modules\bluebird\js\release\async.js:138:12)
    at _drainQueue (C:\d\code\js\mbot\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (C:\d\code\js\mbot\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues (C:\d\code\js\mbot\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)
  name: 'SequelizeDatabaseError',
  parent:

该应用为nodejs 10.11.0-/express 4.16.3/EJS 2.6.1

在浏览器上,它显示以下错误:

This site can’t be reached
localhost refused to connect.
Search Google for localhost 3000 api orders
ERR_CONNECTION_REFUSED

orders = [];进给时,查看页面很好。这是查看代码:

<table class="table table-hover table-striped">
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">Order Date</th>
            <th scope="col">Customer</th>
            <th scope="col">Order#</th>
            <th scope="col">Amount(RMB)</th>
            <th scope="col">Amount(USDT)</th>
            <th scope="col">Paid?</th>
          </tr>
        </thead>
        <tbody>
            <% for(var i =0; i < item_list.length; i++){%>
                    <tr>
                      <td><%= i + 1 %></td>
                      <td><%= item_list[i].order_datetime %></td>
                      <td><%= item_list[i].customer_name %></td>
                      <td><%= item_list[i].order_no %></td>
                      <td><%= item_list[i].amount_rmb %></td>
                      <td><%= item_list[i].amount_crypto %></td>
                      <td><%= item_list[i].payment_rcvd %></td>
                    </tr>

            <% } %>
        </tbody>
 </table>
 <table class="table table-striped">
      <tr>
        <th>

           <input type="button" value="Close" onclick="history.back(-1)" />
        </th>
      </tr>
 </table>     

我是nodejs应用的新手,不确定导致错误的原因。

1 个答案:

答案 0 :(得分:0)

Sequelize使用复数作为表名的默认值,而users的名称起作用。这是有关Sequelize table name change的文章。