Sails.JS + MySQL:'where子句'中的未知列'NaN'

时间:2015-01-08 08:40:39

标签: mysql sails.js waterline

这是我第一次将sails.js与mySQL数据库一起使用,我对这个错误感到很困惑。

我有一个控制器&模型叫做公司'。它涉及表'公司'在mySQL数据库中。该表本身与两个名为' module'模块的表有一对多关联。和'用户' (每个用户/模块必须与一个公司ID连接)。我在MySQL数据库中设置了外键。

问题是..每次我从这个控制器打开任何页面/动作时,都会出现这个错误:

    error: Sending 500 ("Server Error") response: 
 Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'where clause'
    at Query.Sequence._packetToError (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:30:14)
    at Query.ErrorPacket (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:82:18)
    at Protocol._parsePacket (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:213:24)
    at Parser.write (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:62:12)
    at Protocol.write (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:37:16)
    at Socket.<anonymous> (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:75:28)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:764:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:426:10)
    --------------------
    at Protocol._enqueue (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:110:48)


    at PoolConnection.Connection.query (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:166:25)
    at PoolConnection.liveConnection.query (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/lib/connections/spawn.js:98:16)
    at __FIND__ (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/lib/adapter.js:836:20)
    at afterwards (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/lib/connections/spawn.js:104:5)
    at /Users/alanyudh/Sites/matta/node_modules/sails-mysql/lib/connections/spawn.js:40:7
    at Pool.<anonymous> (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:51:14)
    at Handshake.Sequence.end (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:78:24)
    at Handshake.Sequence.OkPacket (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:87:8)
    at Protocol._parsePacket (/Users/alanyudh/Sites/matta/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:213:24)

Details:  Error: ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'where clause'

这是我的公司型号:

    module.exports = {
  attributes: {
      name:{
        type:"string",
        required:true,
        unique:true,
        minLength: 2
      },
      type:{
        type:"string",
        enum: ['hq','sub'],
        defaultsTo: 'hq'
      },     
      desc:{
        type:"text",
        required:true
      },
      logo: {
        type: 'string'
      },
      address: {
        type: 'text'
      },
      city: {
        type: 'string'
      },
      region: {
        type: 'string'
      },
      country: {
        type: 'string'
      },
      zipcode: {
        type: 'string'
      },
      phone_number: {
        type: 'string'
      },
      website: {
        type: 'string'
      }
  },
};

我尝试使用&#39; autoPK:false&#39;,&#39; schema:true&#39;,添加&#39; columnName / fieldName&#39;,但它们都没有工作。

错误是什么意思? 我该如何解决?

非常感谢。

1 个答案:

答案 0 :(得分:4)

Oppening localhost:1337 / company / index是你的问题,不是任何mysql或其他orm问题!

这是一个路由配置探测器。当您打开此URL时,默认的sails行为是您尝试通过默认的REST api访问特定的公司记录。检查默认休息routes behavior

为了在您的案例中更加明确,sails会解释您正在使用id&#34; index&#34;查询特定公司。这不是数字NaN因此您会收到此错误。

  

RESTful路线,路径始终为/:modelIdentity或 /:modelIdentity /:id。