Check MySQL errors [[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(JSON_OBJECT())…]

Error when setting default values in JSON type in ALTER TABLE in MySQL.

[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(JSON_OBJECT())...

What I wanted to do was to add columns to an existing table, but setting default values resulted in an error.

Conclusion, versions prior to MySQL 8.0.13 cannot set default values for the JSON type.

I will describe the process I went through to find out.

目次

Check the version of MySQL

command and checked the MySQL version.
It was found to be 5.7.30.

select version();

Check the documentation for your version of MySQL.

I refer to the official documentation.

The Explicit Default Handling section states that [The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default value. JSON data types cannot be assigned a default value.

It is common to refer to the latest version and mistakenly think that it can be done. Be careful.

Summay

In both MySQL and libraries, different versions can and cannot do different things, so it is important to look at the version accurately.

よかったらシェアしてね!
目次