mysql / nodejs错误

时间:2014-08-03 07:53:54

标签: mysql node.js

我一直在努力解决这个问题几个小时,但可以搞清楚。

/Users/Spencer/stuq-sockets/node_modules/mysql/lib/protocol/Parser.js:82
    throw err;
          ^
Error: ER_NO_DEFAULT_FOR_FIELD: Field 'subject' doesn't have a default value
at Query.Sequence._packetToError (/Users/Spencer/stuq-sockets/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
at Query.ErrorPacket (/Users/Spencer/stuq-sockets/node_modules/mysql/lib/protocol/sequences/Query.js:82:18)
at Protocol._parsePacket (/Users/Spencer/stuq-sockets/node_modules/mysql/lib/protocol/Protocol.js:251:24)
at Parser.write (/Users/Spencer/stuq-sockets/node_modules/mysql/lib/protocol/Parser.js:77:12)
at Protocol.write (/Users/Spencer/stuq-sockets/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/Users/Spencer/stuq-sockets/node_modules/mysql/lib/Connection.js:82:28)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:745:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:407:10)
--------------------
at Protocol._enqueue (/Users/Spencer/stuq-sockets/node_modules/mysql/lib/protocol/Protocol.js:135:48)
at Connection.query (/Users/Spencer/stuq-sockets/node_modules/mysql/lib/Connection.js:184:25)
at Object.<anonymous> (/Users/Spencer/stuq-sockets/setup1.js:127:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3

它适用于我的几乎所有查询,除了这一个,我无法弄清楚原因。 mysql可能会损坏还是我查询的语法?

connection.query("insert into course(title, calendar_link, 
  syllabus_link, office_hours, "
  + "instructor, website_link, lecture_times) "
  + "values(\"" + doc["courseName"] + "\", \""
  + doc["calendar"] + "\", \"" + doc["syllabus"] + "\", \""
  + doc["officeHours"] + "\", \"" + doc["instructor"] + "\", \""
  + doc["website"] + "\", \"" + doc["lectureTime"] + "\")",
  function(err, result){
  if(err) throw err;

  c_id = result.insertId;


  tutors = doc["tutors"];
  students = doc["students"];

  addTutor_AccountTable(c_id, tutors, 0, function() {
     // Add students?
     console.log('TODO: Add students');

  });

  addStudent_AccountTable(c_id, students, 0, function() {
     connection.end();
  });
});

1 个答案:

答案 0 :(得分:3)

subject列添加到您的插入内容

或 转到phpmyadmin更改subject添加默认值或选中允许空复选框