3

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

dkran
  • 284
  • 2
  • 4
  • 16

2 Answers2

6

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.

Bizzycola
  • 119
  • 8
  • quick second question, if you're good with sql and financial systems, is the default way to timestamp something still the # of ms since like 1970 or whatever – dkran Mar 16 '15 at 02:20
  • 1
    @dkran MySQL 5.6+ has built-in timestamp functionality where the database can supply the default values, with a granularity of seconds, milliseconds, or microseconds. http://dev.mysql.com/doc/refman/5.6/en/datetime.html (versions before 5.5 have similar but more limited capabilities). – Michael - sqlbot Mar 16 '15 at 10:27
-1

I faced same problem and then I found that I had a field which is set to be AutoIncremented but I forgot to set that Auto Incremented So if you have a field that requires a value and has no default So set it Auto increment, Primary key,NotNull.