Waterline sails-msql ER_NO_SUCH_TABLE:表不存在

时间:2015-07-25 10:46:07

标签: sails.js waterline

我只是在尝试使用sails.js更新'bookings'mysql字段时才收到错误。 这是预订模型:

module.exports = {

    tableName: 'bookings',
    adapter: 'mysql',
    autoCreatedAt: true,
    autoUpdatedAt: true,

  attributes: {

      id: {type: 'integer',autoIncrement: true,primaryKey: true},
      booking_n: {type: 'integer'},
      customer: { model:'customers'},
      room: {type: 'string'},
      departure: {type: 'date'},
      createdAt: {type: 'date'},
      updatedAt: {type: 'date'},
      invoice: {mode:'invoices'}
    }
};

正如您所看到的,有2个“一对多”关联,(发票可以有多个预订等),这里是发票模型:

module.exports = {

    tableName:'invoices',
    adapter: 'mysql',
    autoPK:false,
    autoCreatedAt: true,
    autoUpdatedAt: true,

attributes: {

id: {type: 'integer', autoIncrement: true, primaryKey: true},
doc_mod: {type:'string'},
doc_n: {type:'integer'},
createdAt: {type:'date'},
updatedAt: {type:'date'},
invoice_line: {collection:'invoice_lines', via:'invoice'},
customer: {model:'customers'},
bookings:{collection:'bookings', via:'invoice'}
  }
}

来自Angular我想用新invoice.id:

更新预订模型
Update:function(bookingObj){

    var BookingResource = $resource(IP_ADDRESSES.dbserver+'bookings/:id',{
        id: '@id'
    },{
        'update': {
            method: 'PUT'
        }
     });
    return BookingResource.update({id: bookingObj.id}, bookingObj).$promise;
}

但是我从sails控制台日志中得到了这个错误:

error: Sending 500 ("Server Error") response:
 Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_NO_SUCH_TABLE: Table 'prestige2.bookings_invoice__invoices_bookings' doesn't exist
    at Query.Sequence._packetToError (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\sequence
s\Sequence.js:48:14)
    at Query.ErrorPacket (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\sequences\Query.js:8
3:18)
    at Protocol._parsePacket (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\Protocol.js:271:
23)
    at Parser.write (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\Parser.js:77:12)
    at Protocol.write (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\Connection.js:92:28)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:529:20)
    --------------------
    at Protocol._enqueue (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\Protocol.js:135:48)
    at PoolConnection.Connection.query (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\Connection.js:1
97:25)
    at __FIND__ (C:\prestigeserver\node_modules\sails-mysql\lib\adapter.js:836:20)
    at Object.module.exports.adapter.find (C:\prestigeserver\node_modules\sails-mysql\lib\adapter.js:803:9)
    at Array.async.auto.findRecords (C:\prestigeserver\node_modules\sails-mysql\lib\adapter.js:1056:21)
    at C:\prestigeserver\node_modules\sails-mysql\node_modules\async\lib\async.js:484:38
    at _each (C:\prestigeserver\node_modules\sails-mysql\node_modules\async\lib\async.js:46:13)
    at Object.async.auto (C:\prestigeserver\node_modules\sails-mysql\node_modules\async\lib\async.js:455:9)
    at __DESTROY__ (C:\prestigeserver\node_modules\sails-mysql\lib\adapter.js:1053:15)
    at afterwards (C:\prestigeserver\node_modules\sails-mysql\lib\connections\spawn.js:84:5)
    at C:\prestigeserver\node_modules\sails-mysql\lib\connections\spawn.js:40:7
    at Ping.onPing [as _callback] (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\Pool.js:94:5)
    at Ping.Sequence.end (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.j
s:96:24)
    at Ping.Sequence.OkPacket (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\sequences\Seque
nce.js:105:8)
    at Protocol._parsePacket (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\Protocol.js:271:
23)
    at Parser.write (C:\prestigeserver\node_modules\sails-mysql\node_modules\mysql\lib\protocol\Parser.js:77:12)

Details:  Error: ER_NO_SUCH_TABLE: Table 'prestige2.bookings_invoice__invoices_bookings' doesn't exist
来自Postman的

我可以看到客户端正在发送这个对象:

{"customer":{"id":1,"name":"John","surname":"Doe","company":"Apple","address":"5 avenue","street_n":"9A","cap":"1000","city":"NY","province":"NY","country":"USA","nationality":"USA","phone":"000000","email":"johndoe@gmail.com","tax_n":"3456756754","notes":"nope","createdAt":"2015-04-25T23:19:07.000Z","updatedAt":"2015-07-24T17:13:30.000Z"},"id":92,"booking_n":1437818426364,"room":"Suite ","guest":"Doe","guests_n":2,"arrival":"2015-07-20T22:00:00.000Z","departure":"2015-07-24T22:00:00.000Z","createdAt":"2015-07-24T22:00:00.000Z","updatedAt":"2015-07-25T10:00:48.000Z","invoice":88}

1 个答案:

答案 0 :(得分:0)

我发现了自己的错误:正如我之前的评论中所提到的,错误是指错误的模型关联,在我的情况下由于拼写错误:我写了"C:\\opencv2.4.9\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml" ,而不是invoice: {mode:'invoices'}。< / p>