Tagged: strict mode

SQLSTATE[HY000]: General error: 1364 Field doesn't have a default value

- by Oleg Ivanchenko

I have got an error:

	SQLSTATE[HY000]: General error: 1364 Field 'XXXX' doesn't have a default value

Happened with MySQL 5.7.12, Mac OS X 10.11.5. MySQL installed from a package from mysql.com.

The obvious solution does not work: adding default value into SQL code (default '') generates another error for a TEXT field:

	SQLSTATE[42000]: Syntax error or access violation: 1101 BLOB, TEXT, GEOMETRY or JSON column 'XXXX' can't have a default value

Thus I had to update MySQL settings. The default MySQL strict mode has to be disabled.

In my case there were no /etc/my.cnf file. The default settings were in /usr/local/mysql/support-files/my-default.cnf. I added /etc/my.cnf with the following code in it:

[mysqld]<br>sql_mode=NO_ENGINE_SUBSTITUTION

And of course MySQL should be restarted :-) Look here for more details.

It solved the problem.


« All tags