0

I have been working on fixing this problem for hours but can figure it out.

/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

It works for almost all of my queries except for this one and I can't figure out why. Could mysql be corrupt or maybe the syntax of my query?

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
  • It looks like subject might be a non-nullable column/field in your course table, and your insertion is not setting a value for subject. When you define columns for a table, you can specify whether the column should have a default value. I don't think you've set your subject column this way. This means that you either have to set it in your insert statement or modify your column definition to automatically supply a default value. Commented Aug 3, 2014 at 8:27

1 Answer 1

3

Add subject column to your insert

or go to phpmyadmin change subject add default value or check allow null check box

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.