mysqlsqljsonnode.jsnode-mysql

ER_NO_DEFAULT_FOR_FIELD in MySQL (nodejs rest request)


what does this error mean in mysql?
ER_NO_DEFAULT_FOR_FIELD – “Field doesn’t have a default value” I've found it listed here? http://mysqlserverteam.com/improvements-to-strict-mode-in-mysql/ and got:

{
    "code": "ER_NO_DEFAULT_FOR_FIELD",
    "errno": 1364,
    "sqlState": "HY000",
    "index": 0
}

that reply in a postman request via expressjs, but this is the first table I've seem to have gotten it from. the table has foreign keys so I set default values for the foreign keys, but I still get it. what gives? is the index[0] implying the name, the first json value I sent to the server?

{
    "name":"Cornwall Park Townhouses",
    "line1":"17 Brewster Rd.",
    "city":"Cornwall",
    "state":32,
    "zip":"12518",
    "category":2,
    "account_mgr":1,
    "active":1
}

heres my json


Solution

  • Well my guess is you have a field that requires a value and has no default. So when you insert into your table, if you don't provide a valid value for it, MySQL complains.

    It'd be more help if you'd shown us your tables and maybe insert query as well, but take a look at your fields. If you find one that has no default and you're not doing anything with it, try inserting into it and passing a value for the field, if that solves the issue then you can add a default value for that field or just keep sending information to it.

    If you don't want a default you could set the fields to allow null instead of a default value.