Field 'class' doesn't have a default value

13,872

It seems that it is MySQL error 1364 - Message: Field '%s' doesn't have a default value.

Check the table which you modify. Are there any fields without default values? Also analyze INSERT and UPDATE statements if they do not post these field values.

To fix this error:

  • modify table - set DEFAULT values for fields you need

or

  • pass concrete values to these fields in INSERT/UPDATE statements.
Share:
13,872
Fustigador
Author by

Fustigador

Former cameraman, now developing apps for Android. Drummer, DM and Android developer (in that order)

Updated on June 13, 2022

Comments

  • Fustigador
    Fustigador almost 2 years

    In our app, I have a class describing a person (eye and hair colour, height, etc). Once the form of registering is fulfilled, I click in the submit button, and an exception is thrown:

    Class: java.sql.SQLException
    Message: Field 'class' doesn't have a default value
    

    I am scratching my head about this, because none of the classes have a field named class, for obvious reasons (it's a reserved word), and in the database there is no column named class, neither.

    Any idea why this happens? And how to fix it?

    EDIT:

    I tried this:

    classThrowingExceptionInstance.class=ClassThrowingException
    

    And now it says Cannot set readonly property: class for class ClassThrowingException

  • Fustigador
    Fustigador over 11 years
    Thank you! Looking for closely (it is inherited code, and an inherited database) I found that the class throwing the exception extends another class (let's say, User) wich does not have a property called class, but in the Database it HAS a column named that way. Guess i should set a default value for that column.
  • Devart
    Devart over 11 years
    Look for one more time ;-) This is MySQl error. You should find all errors and fix them.
  • Fustigador
    Fustigador over 11 years
    I finally droped the entire database (we are not yet online), and Hibernate created it again. And now works fine. Thank you Devart :)